#include <bits/stdc++.h>
using namespace std;
#define ld long double
#define ll long long
#define rem 1000000007

typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll, ll> pii;
#define v(x) vector<x>
#define pb(x) push_back(x)
#define ppb() pop_back()
#define mp(x,y) make_pair(x,y)
#define mii map<ll,ll>
#define umii unordered_map<ll,ll>
#define mxheap priority_queue<ll> // Max Heap
#define mnheap priority_queue<ll,vi,greater<ll> > // Min Heap
#define da(type,arr,size) type *arr = new type[n] // Dynamically allocated array

#define f(i,n) for(ll i=0;i<(n);i++)
#define fa(i,a,b) for(ll i=(a);i<(b);i++)
#define far(i,a,b) for(ll i=(a);i>(b);i--)
#define T ll t; cin>>t; while(t--)
#define ff first
#define ss second
#define mem(a,b) memset(a,b,sizeof(a))
#define sz size()

#define setbits(x) __builtin_popcountll(x) // Total set bits in a number
#define zerobits(x) __builtin_ctzll(x) // This will tell me number of zeroes till first set bit
#define all(c) (c).begin(),(c).end()
#define setp(x,y) fixed<<setprecision(y)<<x
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define INF 2e18

// ld dist(ll x1, ll y1, ll x2, ll y2) {
// 	ld ans = round(pow(mod(x2 - x1), 2)) + round(pow(mod(y2 - y1), 2));
// 	ans = sqrt(ans);
// 	return ans;
// }

// ld dist(pii a, pii b) {
// 	ld ans = round(pow(mod(b.ff - a.ff), 2)) + round(pow(mod(b.ss - a.ss), 2));
// 	ans = sqrt(ans);
// 	return ans;
// }
// umii isPrime;
// void SieveOfEratosthenes(ll n)
// {
// 	bool prime[n + 1];
// 	memset(prime, true, sizeof(prime));

// 	for (ll p = 2; p * p <= n; p++)
// 	{
// 		if (prime[p] == true)
// 		{
// 			for (ll i = p * p; i <= n; i += p)
// 				prime[i] = false;
// 		}
// 	}
// 	for (ll p = 2; p <= n; p++)
// 		if (prime[p])
// 			isPrime[p] = 1;;
// }
// ll binaryToDecimal(vi& num)
// {
// 	//string num = n;
// 	ll dec_value = 0;

// 	// Initializing base value to 1, i.e 2^0
// 	ll base = 1;

// 	ll len = num.size();
// 	for (ll i = 0; i < len; i++) {
// 		if (num[i] == 1)
// 			dec_value += base;
// 		base = base * 2;
// 	}

// 	return dec_value;
// }

ll power_mod(ll x, ll y, ll p)
{
	ll res = 1;     // Initialize result

	x = x % p; // Update x if it is more than or
	// equal to p

	if (x == 0) return 0; // In case x is divisible by p;

	while (y > 0)
	{
		// If y is odd, multiply x with result
		if (y & 1)
			res = (res * x) % p;

		// y must be even now
		y = y >> 1; // y = y/2
		x = (x * x) % p;
	}
	return res;
}

ll power(ll x, ll y) {
	ll res = 1;
	while (y) {
		if (y % 2 == 1) {
			res *= x;
			y--;
		}
		else {
			x *= (x);
			y /= 2;
		}
	}
	return res;
}

// ll sq(ll n) {
// 	return (n * n);
// }

// ll gcdExtended(ll a, ll b, ll *x, ll *y);

// // Function to find modulo inverse of a
// ll modInverse(ll a, ll m)
// {
// 	ll x, y;
// 	ll g = gcdExtended(a, m, &x, &y);
// 	ll res = (x % m + m) % m;
// 	return res;

// }

// ll gcdExtended(ll a, ll b, ll *x, ll *y)
// {
// 	// Base Case
// 	if (a == 0)
// 	{
// 		*x = 0, *y = 1;
// 		return b;
// 	}

// 	ll x1, y1; // To store results of recursive call
// 	ll gcd = gcdExtended(b % a, a, &x1, &y1);

// 	// Update x and y using results of recursive
// 	// call
// 	*x = y1 - (b / a) * x1;
// 	*y = x1;

// 	return gcd;
// }

void primeFactors(ll n, umii& mp)
{
	unordered_map<ll, bool> lop;
	while (n % 2 == 0)
	{
		lop[2] = 1;
		n = n / 2;
	}
	for (ll i = 3; i <= sqrt(n); i = i + 2)
	{
		while (n % i == 0)
		{
			lop[i] = 1;
			n = n / i;
		}
	}
	if (n > 2)
		lop[n] = 1;
	for (auto it : lop) {
		if (it.ss) {
			mp[it.ff]++;
		}
	}
}

// void decToBinary(ll n, vi& binaryNum)
// {
// 	ll i = 0;
// 	while (n > 0) {
// 		binaryNum[i] = n % 2;
// 		n = n / 2;
// 		i++;
// 	}
// }

// ll getAns(umii& a, umii& c) {
// 	umii kitne;
// 	for (auto it : c) {
// 		if (it.ss % 2 == 1) {
// 			return -1;
// 		}
// 		kitne[it.ff] = it.ss / 2;
// 	}
// 	vi aMeAyega;
// 	for (auto it : kitne) {
// 		ll diff = mod(it.ss - a[it.ff]);
// 		f(i, diff) {
// 			aMeAyega.pb(it.ff);
// 		}

// 	}
// 	ll ans = 0;
// 	sort(all(aMeAyega));

// 	f(i, aMeAyega.sz / 2) {
// 		ans += aMeAyega[i];
// 	}
// 	return ans;
// }
ll gcd(ll a, ll b) {
	return __gcd(a, b);
}

// ll factMod(ll n) {
// 	ll ans = 1;
// 	fa(i, 1, n + 1) {
// 		ans *= i;
// 		ans %= rem;
// 	}
// 	return ans;
// }

// string numToString(ll num){
// 	string ans = "";
// 	while(num){
// 		ll temp = num%10;
// 		ans+=to_string(temp%2);
// 		num/=2;
// 	}
// 	while(ans.sz!=18){
// 		ans+='0';
// 	}
// 	reverse(ans.begin(),ans.end());
// 	return ans;
// }

// void SieveOfEratosthenes(ll n, umii& mp)
// {
// 	// Create a boolean array "prime[0..n]" and initialize
// 	// all entries it as true. A value in prime[i] will
// 	// finally be false if i is Not a prime, else true.
// 	bool prime[n + 1];
// 	memset(prime, true, sizeof(prime));

// 	for (int p = 2; p * p <= n; p++)
// 	{
// 		// If prime[p] is not changed, then it is a prime
// 		if (prime[p] == true)
// 		{
// 			// Update all multiples of p greater than or
// 			// equal to the square of it
// 			// numbers which are multiple of p and are
// 			// less than p^2 are already been marked.
// 			for (int i = p * p; i <= n; i += p)
// 				prime[i] = false;
// 		}
// 	}

// 	// Print all prime numbers
// 	for (int p = 2; p <= n; p++)
// 		if (prime[p])
// 			mp[p]++;
// }

// void printDivisors(ll n, umii& mp)
// {
// 	// Note that this loop runs till square root
// 	for (ll i = 1; i <= sqrt(n); i++)
// 	{
// 		if (n % i == 0)
// 		{
// 			// If divisors are equal, print only one
// 			if (n / i == i) {
// 				mp[i]++;
// 			}

// 			else // Otherwise print both
// 				mp[i]++, mp[n / i]++;
// 		}
// 	}
// }

bool dfs(ll src, unordered_map<ll, vi>& adjList, vector<bool>& visited, ll level, vi& set1, vi& set2, vi& parent) {
	visited[src] = true;

	if (level % 2 == 0) {
		set1.pb(src);
	}
	else {
		set2.pb(src);
	}
	bool ans = true;
	for (ll j : adjList[src]) {
		if (visited[j] && j != parent[src]) {
			return false;
		}
		else if (!visited[j]) {
			parent[j] = src;
			ans &= dfs(j, adjList, visited, level + 1, set1, set2, parent);
		}
	}
	return ans;
}

int main() {
	fast
	ll n, m;
	cin >> n >> m;
	unordered_map<ll, vi> adjList;
	f(i, m) {
		ll u, v;
		cin >> u >> v;
		adjList[u].pb(v);
		adjList[v].pb(u);
	}
	std::vector<bool> visited(n + 1, false);
	vi parent(n + 1);
	f(i, n + 1) parent[i] = i;
	vector<ll> set1;
	vector<ll> set2;
	bool ans = dfs(1, adjList, visited, 0, set1, set2, parent);
	if (!ans)
		cout << -1 << endl;
	else {
		cout << set1.sz << endl;
		f(i, set1.sz) {
			cout << set1[i] << " ";
		}
		cout << endl;
		cout << set2.sz << endl;
		f(i, set2.sz) {
			cout << set2[i] << " ";
		}
		cout << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define fill(a, b) memset(a, b, sizeof(a))
#define endl "\n"
typedef long long ll;
typedef long double lld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
typedef pair<ll, ll> pll;
typedef pair<ll, pair<ll, ll>> plll;

const int N = 1000010;
const ll MOD = 1e9 + 7;

vector<bool> visited;
vi value;
vector<vi> adj;

void dfs(int u) {
  visited[u] = true;
  for (auto x : adj[u]) {
    if (!visited[x]) {
      if (value[x] == -1) {
        value[x] = 1 - value[u];
      }
      dfs(x);
    }
  }
}

void solve() {
  int n, m;
  cin >> n >> m;
  visited.assign(n + 1, false);
  value.assign(n + 1, -1);
  adj.assign(n + 1, {});
  vii edge;
  for (int i = 0; i < m; i++) {
    ii a;
    cin >> a.first >> a.second;
    adj[a.first].push_back(a.second);
    adj[a.second].push_back(a.first);
    edge.push_back(a);
  }
  set<int> ans1, ans2;
  for (auto x : edge) {
    if (!visited[x.first]) {
      value[edge[0].first] = 1;
      dfs(edge[0].first);
    }
  }
  for (auto x : edge) {
    if (value[x.first] == 0 && value[x.second] == 0) {
      cout << -1 << endl;
      return;
    }
    if (value[x.first] == 1 && value[x.second] == 1) {
      cout << -1 << endl;
      return;
    }
    if (value[x.first] == 0 && value[x.second] == 1) {
      ans1.insert(x.first);
      ans2.insert(x.second);
    }
    if (value[x.first] == 1 && value[x.second] == 0) {
      ans1.insert(x.second);
      ans2.insert(x.first);
    }
  }
  cout << ans1.size() << endl;
  for (auto x : ans1) cout << x << " ";
  cout << endl;
  cout << ans2.size() << endl;
  for (auto x : ans2) cout << x << " ";
  cout << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  // int t;
  // cin >> t;
  // for (int i = 0; i < t; i++) {
  //   solve();
  // }
  solve();
}


#include <bits/stdc++.h>
using namespace std;

#define fill(a, b) memset(a, b, sizeof(a))
#define endl "\n"
typedef long long ll;
typedef long double lld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
typedef pair<ll, ll> pll;
typedef pair<ll, pair<ll, ll>> plll;

const int N = 1000010;
const ll MOD = 1e9 + 7;

vector<bool> visited;
vi value;
vector<vi> adj;

void dfs(int u) {
  visited[u] = true;
  for (auto x : adj[u]) {
    if (!visited[x]) {
      if (value[x] == -1) {
        value[x] = 1 - value[u];
      }
      dfs(x);
    }
  }
}

void solve() {
  int n, m;
  cin >> n >> m;
  visited.assign(n + 1, false);
  value.assign(n + 1, -1);
  adj.assign(n + 1, {});
  vii edge;
  for (int i = 0; i < m; i++) {
    ii a;
    cin >> a.first >> a.second;
    adj[a.first].push_back(a.second);
    adj[a.second].push_back(a.first);
    edge.push_back(a);
  }
  set<int> ans1, ans2;
  for (auto x : edge) {
    if (!visited[x.first]) {
      value[x.first] = 1;
      dfs(edge[0].first);
    }
  }
  for (auto x : edge) {
    if (value[x.first] == 0 && value[x.second] == 0) {
      cout << -1 << endl;
      return;
    }
    if (value[x.first] == 1 && value[x.second] == 1) {
      cout << -1 << endl;
      return;
    }
    if (value[x.first] == 0 && value[x.second] == 1) {
      ans1.insert(x.first);
      ans2.insert(x.second);
    }
    if (value[x.first] == 1 && value[x.second] == 0) {
      ans1.insert(x.second);
      ans2.insert(x.first);
    }
  }
  cout << ans1.size() << endl;
  for (auto x : ans1) cout << x << " ";
  cout << endl;
  cout << ans2.size() << endl;
  for (auto x : ans2) cout << x << " ";
  cout << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  // int t;
  // cin >> t;
  // for (int i = 0; i < t; i++) {
  //   solve();
  // }
  solve();
}


#include <bits/stdc++.h>
using namespace std;

#define fill(a, b) memset(a, b, sizeof(a))
#define endl "\n"
typedef long long ll;
typedef long double lld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
typedef pair<ll, ll> pll;
typedef pair<ll, pair<ll, ll>> plll;

const int N = 1000010;
const ll MOD = 1e9 + 7;

vector<bool> visited;
vi value;
vector<vi> adj;

void dfs(int u) {
  visited[u] = true;
  for (auto x : adj[u]) {
    if (!visited[x]) {
      if (value[x] == -1) {
        value[x] = 1 - value[u];
      }
      dfs(x);
    }
  }
}

void solve() {
  int n, m;
  cin >> n >> m;
  visited.assign(n + 1, false);
  value.assign(n + 1, -1);
  adj.assign(n + 1, {});
  vii edge;
  for (int i = 0; i < m; i++) {
    ii a;
    cin >> a.first >> a.second;
    adj[a.first].push_back(a.second);
    adj[a.second].push_back(a.first);
    edge.push_back(a);
  }
  set<int> ans1, ans2;
  for (auto x : edge) {
    if (!visited[x.first]) {
      value[x.first] = 1;
      dfs(x.first);
    }
  }
  for (auto x : edge) {
    if (value[x.first] == 0 && value[x.second] == 0) {
      cout << -1 << endl;
      return;
    }
    if (value[x.first] == 1 && value[x.second] == 1) {
      cout << -1 << endl;
      return;
    }
    if (value[x.first] == 0 && value[x.second] == 1) {
      ans1.insert(x.first);
      ans2.insert(x.second);
    }
    if (value[x.first] == 1 && value[x.second] == 0) {
      ans1.insert(x.second);
      ans2.insert(x.first);
    }
  }
  cout << ans1.size() << endl;
  for (auto x : ans1) cout << x << " ";
  cout << endl;
  cout << ans2.size() << endl;
  for (auto x : ans2) cout << x << " ";
  cout << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  // int t;
  // cin >> t;
  // for (int i = 0; i < t; i++) {
  //   solve();
  // }
  solve();
}


#include <bits/stdc++.h>
using namespace std;

#define fill(a, b) memset(a, b, sizeof(a))
#define endl "\n"
typedef long long ll;
typedef long double lld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
typedef pair<ll, ll> pll;
typedef pair<ll, pair<ll, ll>> plll;

const int N = 1000010;
const ll MOD = 1e9 + 7;

vector<bool> visited;
vi value;
vector<vi> adj;

void dfs(int u) {
  visited[u] = true;
  for (auto x : adj[u]) {
    if (!visited[x]) {
      if (value[x] == -1) {
        value[x] = 1 - value[u];
      }
      dfs(x);
    }
  }
}

void solve() {
  int n, m;
  cin >> n >> m;
  visited.assign(n + 1, false);
  value.assign(n + 1, -1);
  adj.assign(n + 1, {});
  vii edge;
  for (int i = 0; i < m; i++) {
    ii a;
    cin >> a.first >> a.second;
    adj[a.first].push_back(a.second);
    adj[a.second].push_back(a.first);
    edge.push_back(a);
  }
  set<int> ans1, ans2;
  value[edge[0].first] = 1;
  dfs(edge[0].first);
  for (auto x : edge) {
    if (value[x.first] == 0 && value[x.second] == 0) {
      cout << -1 << endl;
      return;
    }
    if (value[x.first] == 1 && value[x.second] == 1) {
      cout << -1 << endl;
      return;
    }
    if (value[x.first] == 0 && value[x.second] == 1) {
      ans1.insert(x.first);
      ans2.insert(x.second);
    }
    if (value[x.first] == 1 && value[x.second] == 0) {
      ans1.insert(x.second);
      ans2.insert(x.first);
    }
  }
  cout << ans1.size() << endl;
  for (auto x : ans1) cout << x << " ";
  cout << endl;
  cout << ans2.size() << endl;
  for (auto x : ans2) cout << x << " ";
  cout << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  // int t;
  // cin >> t;
  // for (int i = 0; i < t; i++) {
  //   solve();
  // }
  solve();
}


#include <bits/stdc++.h>
using namespace std;

#define fill(a, b) memset(a, b, sizeof(a))
#define endl "\n"
typedef long long ll;
typedef long double lld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
typedef pair<ll, ll> pll;
typedef pair<ll, pair<ll, ll>> plll;

const int N = 1000010;
const ll MOD = 1e9 + 7;

vector<bool> visited;
vi value;
vector<vi> adj;

void dfs(int u) {
  visited[u] = true;
  for (auto x : adj[u]) {
    if (!visited[x]) {
      if (value[x] == -1) {
        value[x] = 1 - value[u];
      }
      dfs(x);
    }
  }
}

void solve() {
  int n, m;
  cin >> n >> m;
  visited.assign(n + 1, false);
  value.assign(n + 1, -1);
  adj.assign(n + 1, {});
  vii edge;
  for (int i = 0; i < m; i++) {
    ii a;
    cin >> a.first >> a.second;
    adj[a.first].push_back(a.second);
    adj[a.second].push_back(a.first);
    edge.push_back(a);
  }
  set<int> ans1, ans2;
  value[1] = 0;
  dfs(1);
  for (auto x : edge) {
    if (value[x.first] == 0 && value[x.second] == 0) {
      cout << -1 << endl;
      return;
    }
    if (value[x.first] == 1 && value[x.second] == 1) {
      cout << -1 << endl;
      return;
    }
    if (value[x.first] == 0 && value[x.second] == 1) {
      ans1.insert(x.first);
      ans2.insert(x.second);
    }
    if (value[x.first] == 1 && value[x.second] == 0) {
      ans1.insert(x.second);
      ans2.insert(x.first);
    }
  }
  cout << ans1.size() << endl;
  for (auto x : ans1) cout << x << " ";
  cout << endl;
  cout << ans2.size() << endl;
  for (auto x : ans2) cout << x << " ";
  cout << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  // int t;
  // cin >> t;
  // for (int i = 0; i < t; i++) {
  //   solve();
  // }
  solve();
}


#include <bits/stdc++.h>
using namespace std;

#define fill(a, b) memset(a, b, sizeof(a))
#define endl "\n"
typedef long long ll;
typedef long double lld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
typedef pair<ll, ll> pll;
typedef pair<ll, pair<ll, ll>> plll;

const int N = 1000010;
const ll MOD = 1e9 + 7;

vector<bool> visited;
vi value;
vector<vi> adj;

void dfs(int u) {
  visited[u] = true;
  for (auto x : adj[u]) {
    if (!visited[x]) {
      if (value[x] == -1) {
        value[x] = 1 - value[u];
      }
      dfs(x);
    }
  }
}

void solve() {
  int n, m;
  cin >> n >> m;
  visited.assign(n + 1, false);
  value.assign(n + 1, -1);
  adj.assign(n + 1, {});
  vii edge;
  for (int i = 0; i < m; i++) {
    ii a;
    cin >> a.first >> a.second;
    adj[a.first].push_back(a.second);
    adj[a.second].push_back(a.first);
    edge.push_back(a);
  }
  set<int> ans1, ans2;
  value[edge[0].first] = 0;
  dfs(edge[0].first);
  for (auto x : edge) {
    if (value[x.first] == 0 && value[x.second] == 0) {
      cout << -1 << endl;
      return;
    }
    if (value[x.first] == 1 && value[x.second] == 1) {
      cout << -1 << endl;
      return;
    }
    if (value[x.first] == 0 && value[x.second] == 1) {
      ans1.insert(x.first);
      ans2.insert(x.second);
    }
    if (value[x.first] == 1 && value[x.second] == 0) {
      ans1.insert(x.second);
      ans2.insert(x.first);
    }
  }
  cout << ans1.size() << endl;
  for (auto x : ans1) cout << x << " ";
  cout << endl;
  cout << ans2.size() << endl;
  for (auto x : ans2) cout << x << " ";
  cout << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  // int t;
  // cin >> t;
  // for (int i = 0; i < t; i++) {
  //   solve();
  // }
  solve();
}


#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector <int>
#define vl vector <ll>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define MOD 1000000007
ll power(ll a, ll b) { //a^b
	ll res = 1;
	a = a % MOD;
	while (b > 0) {
		if (b & 1) {res = (res * a) % MOD; b--;}
		a = (a * a) % MOD;
		b >>= 1;
	}
	return res;
}

ll gcd(ll a, ll b) {return (b == 0) ? a : gcd(b, a % b);}

vector <vl> adj(200005);
vl vis(200005, 0);
int f = 0;

void dfs(ll u, vl &cnt, ll c) {
	cnt[u] = c;
	for (auto it : adj[u]) {
		if (!vis[it] && cnt[it] == -1) {
			vis[it] = 1;
			dfs(it, cnt, 1 - c);
		}
		if (cnt[it] == cnt[u]) {
			f = 1;
		}
	}
}

int main() {
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n, m;
	cin >> n >> m;
	for (ll i = 0; i < m; i++) {
		ll u, v;
		cin >> u >> v;
		u--;
		v--;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	set <ll> a;
	set <ll> b;
	for (ll i = 0; i < n; i++) {
		vl cnt(n, -1);
		if (!vis[i]) {
			vis[i] = 1;
			cnt[i] = 0;
			dfs(i, cnt, 0);
		}
		for (ll i = 0; i < n; i++) {
			if (cnt[i] == 0)
				a.insert(i + 1);
			else if (cnt[i] == 1)
				b.insert(i + 1);
		}
	}
	if (f)
		cout << "-1\n";
	else {
		cout << a.size() << "\n";
		for (auto it : a)
			cout << it << " ";
		cout << "\n";
		cout << b.size() << "\n";
		for (auto it : b)
			cout << it << " ";
		cout << "\n";
	}
}


#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector <int>
#define vl vector <ll>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define MOD 1000000007
ll power(ll a, ll b) { //a^b
	ll res = 1;
	a = a % MOD;
	while (b > 0) {
		if (b & 1) {res = (res * a) % MOD; b--;}
		a = (a * a) % MOD;
		b >>= 1;
	}
	return res;
}

ll gcd(ll a, ll b) {return (b == 0) ? a : gcd(b, a % b);}

vector <vl> adj(200005);
vl vis(200005, 0);
int f = 0;

void dfs(ll u, vl &cnt, ll c) {
	cnt[u] = c;
	for (auto it : adj[u]) {
		if (!vis[it] && cnt[it] == -1) {
			vis[it] = 1;
			dfs(it, cnt, 1 - c);
		}
		if (cnt[it] == cnt[u]) {
			f = 1;
		}
	}
}

int main() {
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n, m;
	cin >> n >> m;
	for (ll i = 0; i < m; i++) {
		ll u, v;
		cin >> u >> v;
		u--;
		v--;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	vl a;
	vl b;
	for (ll i = 0; i < n; i++) {
		if(f)
			break;
		vl cnt(n, -1);
		if (!vis[i]) {
			vis[i] = 1;
			cnt[i] = 0;
			dfs(i, cnt, 0);
			for (ll i = 0; i < n; i++) {
				if (cnt[i] == 0)
					a.pb(i + 1);
				else if (cnt[i] == 1)
					b.pb(i + 1);
			}
		}

	}
	if (f)
		cout << "-1\n";
	else {
		cout << a.size() << "\n";
		for (auto it : a)
			cout << it << " ";
		cout << "\n";
		cout << b.size() << "\n";
		for (auto it : b)
			cout << it << " ";
		cout << "\n";
	}
}


#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector <int>
#define vl vector <ll>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define MOD 1000000007
ll power(ll a, ll b) { //a^b
	ll res = 1;
	a = a % MOD;
	while (b > 0) {
		if (b & 1) {res = (res * a) % MOD; b--;}
		a = (a * a) % MOD;
		b >>= 1;
	}
	return res;
}

ll gcd(ll a, ll b) {return (b == 0) ? a : gcd(b, a % b);}

vector <vl> adj(200005);
vl vis(200005, 0);
int f = 0;

void dfs(ll u, vector <ll>& cnt, vector <ll>& viss, ll c) {
	cnt[u] = c;
	for (auto it : adj[u]) {
		if (!vis[it] && cnt[it] == -1) {
			vis[it] = 1;
			viss.pb(it);
			dfs(it, cnt, viss, 1 - c);
		}
		if (cnt[it] == cnt[u]) {
			f = 1;
		}
	}
}

int main() {
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n, m;
	cin >> n >> m;
	for (ll i = 0; i < m; i++) {
		ll u, v;
		cin >> u >> v;
		u--;
		v--;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	vl a;
	vl b;
	vl cnt(n, -1);
	for (ll i = 0; i < n; i++) {
		if (f)
			break;

		vl viss;
		if (!vis[i]) {

			viss.pb(i);
			vis[i] = 1;
			cnt[i] = 0;
			dfs(i, cnt, viss, 0);
			for (auto i : viss) {
				if (cnt[i] == 0)
					a.pb(i + 1);
				else if (cnt[i] == 1)
					b.pb(i + 1);
			}
		}

	}
	if (f)
		cout << "-1\n";
	else {
		cout << a.size() << "\n";
		for (auto it : a)
			cout << it << " ";
		cout << "\n";
		cout << b.size() << "\n";
		for (auto it : b)
			cout << it << " ";
		cout << "\n";
	}
}


#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector <int>
#define vl vector <ll>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define MOD 1000000007
ll power(ll a, ll b) { //a^b
	ll res = 1;
	a = a % MOD;
	while (b > 0) {
		if (b & 1) {res = (res * a) % MOD; b--;}
		a = (a * a) % MOD;
		b >>= 1;
	}
	return res;
}

ll gcd(ll a, ll b) {return (b == 0) ? a : gcd(b, a % b);}

vector <vl> adj(200005);
vl vis(200005, 0);
int f = 0;

void dfs(ll u, vl &cnt, ll c) {
	cnt[u] = c;
	for (auto it : adj[u]) {
		if (!vis[it] && cnt[it] == -1) {
			vis[it] = 1;
			dfs(it, cnt, 1 - c);
		}
		if (cnt[it] == cnt[u]) {
			f = 1;
		}
	}
}

int main() {
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n, m;
	cin >> n >> m;
	for (ll i = 0; i < m; i++) {
		ll u, v;
		cin >> u >> v;
		u--;
		v--;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	set <ll> a;
	set <ll> b;
	for (ll i = 0; i < n; i++) {
		vl cnt(n, -1);
		if (!vis[i]) {
			vis[i] = 1;
			cnt[i] = 0;
			dfs(i, cnt, 0);
			for (ll i = 0; i < n; i++) {
				if (cnt[i] == 0)
					a.insert(i + 1);
				else if (cnt[i] == 1)
					b.insert(i + 1);
			}
		}

	}
	if (f)
		cout << "-1\n";
	else {
		cout << a.size() << "\n";
		for (auto it : a)
			cout << it << " ";
		cout << "\n";
		cout << b.size() << "\n";
		for (auto it : b)
			cout << it << " ";
		cout << "\n";
	}
}


#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector <int>
#define vl vector <ll>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define MOD 1000000007
ll power(ll a, ll b) { //a^b
	ll res = 1;
	a = a % MOD;
	while (b > 0) {
		if (b & 1) {res = (res * a) % MOD; b--;}
		a = (a * a) % MOD;
		b >>= 1;
	}
	return res;
}

ll gcd(ll a, ll b) {return (b == 0) ? a : gcd(b, a % b);}

vector <vl> adj(200005);
vl vis(200005, 0);
int f = 0;

void dfs(ll u, vector <ll>& cnt, vector <ll>& viss, ll c) {
	cnt[u] = c;
	for (auto it : adj[u]) {
		if (!vis[it] && cnt[it] == -1) {
			vis[it] = 1;
			viss.pb(it);
			dfs(it, cnt, viss, 1 - c);
		}
		if (cnt[it] == cnt[u]) {
			f = 1;
		}
	}
}

int main() {
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n, m;
	cin >> n >> m;
	for (ll i = 0; i < m; i++) {
		ll u, v;
		cin >> u >> v;
		u--;
		v--;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	vl a;
	vl b;
	for (ll i = 0; i < n; i++) {
		if (f)
			break;

		vl viss;
		if (!vis[i]) {
			vl cnt(n, -1);
			viss.pb(i);
			vis[i] = 1;
			cnt[i] = 0;
			dfs(i, cnt, viss, 0);
			for (auto i : viss) {
				if (cnt[i] == 0)
					a.pb(i + 1);
				else if (cnt[i] == 1)
					b.pb(i + 1);
			}
		}

	}
	if (f)
		cout << "-1\n";
	else {
		cout << a.size() << "\n";
		for (auto it : a)
			cout << it << " ";
		cout << "\n";
		cout << b.size() << "\n";
		for (auto it : b)
			cout << it << " ";
		cout << "\n";
	}
}


#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector <int>
#define vl vector <ll>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define MOD 1000000007
ll power(ll a, ll b) { //a^b
	ll res = 1;
	a = a % MOD;
	while (b > 0) {
		if (b & 1) {res = (res * a) % MOD; b--;}
		a = (a * a) % MOD;
		b >>= 1;
	}
	return res;
}

ll gcd(ll a, ll b) {return (b == 0) ? a : gcd(b, a % b);}

vector <vl> adj(200005);
vl vis(200005, 0);
int f = 0;

void dfs(ll u, vector <ll>& cnt, vector <ll>& viss, ll c) {
	cnt[u] = c;
	for (auto it : adj[u]) {
		if (!vis[it] && cnt[it] == -1) {
			vis[it] = 1;
			viss.pb(it);
			dfs(it, cnt, viss, 1 - c);
		}
		if (cnt[it] == cnt[u]) {
			f = 1;
		}
	}
}

int main() {
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n, m;
	cin >> n >> m;
	for (ll i = 0; i < m; i++) {
		ll u, v;
		cin >> u >> v;
		u--;
		v--;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	vl a;
	vl b;
	for (ll i = 0; i < n; i++) {
		if (f)
			break;
		vl cnt(n, -1);
		vl viss;
		if (!vis[i]) {
			viss.pb(i);
			vis[i] = 1;
			cnt[i] = 0;
			dfs(i, cnt, viss, 0);
			for (auto i : viss) {
				if (cnt[i] == 0)
					a.pb(i + 1);
				else if (cnt[i] == 1)
					b.pb(i + 1);
			}
		}

	}
	if (f)
		cout << "-1\n";
	else {
		cout << a.size() << "\n";
		for (auto it : a)
			cout << it << " ";
		cout << "\n";
		cout << b.size() << "\n";
		for (auto it : b)
			cout << it << " ";
		cout << "\n";
	}
}


#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector <int>
#define vl vector <ll>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define MOD 1000000007
ll power(ll a, ll b) { //a^b
	ll res = 1;
	a = a % MOD;
	while (b > 0) {
		if (b & 1) {res = (res * a) % MOD; b--;}
		a = (a * a) % MOD;
		b >>= 1;
	}
	return res;
}

ll gcd(ll a, ll b) {return (b == 0) ? a : gcd(b, a % b);}

vector <vl> adj(200005);
vl vis(200005, 0);
int f = 0;

void dfs(ll u, vl &cnt, vl &viss, ll c) {
	cnt[u] = c;
	for (auto it : adj[u]) {
		if (!vis[it] && cnt[it] == -1) {
			vis[it] = 1;
			viss.pb(it);
			dfs(it, cnt, viss, 1 - c);
		}
		if (cnt[it] == cnt[u]) {
			f = 1;
		}
	}
}

int main() {
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n, m;
	cin >> n >> m;
	for (ll i = 0; i < m; i++) {
		ll u, v;
		cin >> u >> v;
		u--;
		v--;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	vl a;
	vl b;
	for (ll i = 0; i < n; i++) {
		if (f)
			break;
		vl cnt(n, -1);
		vl viss;
		if (!vis[i]) {
			viss.pb(i);
			vis[i] = 1;
			cnt[i] = 0;
			dfs(i, cnt, viss, 0);
			for (auto i : viss) {
				if (cnt[i] == 0)
					a.pb(i + 1);
				else if (cnt[i] == 1)
					b.pb(i + 1);
			}
		}

	}
	if (f)
		cout << "-1\n";
	else {
		cout << a.size() << "\n";
		for (auto it : a)
			cout << it << " ";
		cout << "\n";
		cout << b.size() << "\n";
		for (auto it : b)
			cout << it << " ";
		cout << "\n";
	}
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll MAX = 1e6 + 5;
vector<ll> ans[2];
bool visited[MAX];
ll state[MAX];
ll exists = true;
vector<ll> g[MAX];

bool dfs(ll node, ll cstate)
{
    state[node] = cstate;
    ans[state[node]].push_back(node);
    visited[node] = true;
    bool ret = true;
    for (auto c : g[node])
    {
        if (visited[c] == true && state[c] == state[node])
        {
            return false;
        }
        else if (!visited[c])
        {
            ret = ret && dfs(c, 1 - cstate);
        }
    }
    return ret;
}

int main()
{
    for (int x = 0; x < MAX; x++)
    {
        visited[x] = false;
    }
    ll n, m;
    cin >> n >> m;
    ll a, b;
    ll mm[m];
    for (int x = 0; x < m; x++)
    {
        cin >> a >> b;
        mm[x] = a;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    exists=true;
    for (int x = 1; x <= n; x++)
    {
        if (visited[x] == false && g[x].size() != 0)
            exists = exists && dfs(b, 1);
    }
    if (!exists)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << ans[0].size() << endl;
        for (auto x : ans[0])
        {
            cout << x << " ";
        }
        cout << endl;
        cout << ans[1].size() << endl;
        for (auto x : ans[1])
        {
            cout << x << " ";
        }
        cout << endl;
    }
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll MAX = 1e6 + 5;
vector<ll> ans[2];
bool visited[MAX];
ll state[MAX];
ll exists = true;
vector<ll> g[MAX];

void dfs(ll node, ll cstate)
{
    state[node] = cstate;
    ans[state[node]].push_back(node);
    visited[node] = true;
    for (auto c : g[node])
    {
        if (visited[c] == true && state[c] == state[node])
        {
            exists = false;
        }
        else if (!visited[c])
        {
            dfs(c, 1 - cstate);
        }
    }
}

int main()
{
    for (int x = 0; x < MAX; x++)
    {
        visited[x] = false;
    }
    ll n, m;
    cin >> n >> m;
    ll a, b;
    ll mm[m];
    for (int x = 0; x < m; x++)
    {
        cin >> a >> b;
        mm[x] = a;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    for (int x = 0; x < m; x++)
    {
        if (visited[mm[x]] == false && g[x].size() != 0)
            dfs(b, 1);
    }
    if (!exists)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << ans[0].size() << endl;
        for (auto x : ans[0])
        {
            cout << x << " ";
        }
        cout << endl;
        cout << ans[1].size() << endl;
        for (auto x : ans[1])
        {
            cout << x << " ";
        }
        cout << endl;
    }
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll MAX = 1e6 + 5;
vector<ll> ans[2];
bool visited[MAX];
ll state[MAX];
ll exists = true;
vector<ll> g[MAX];

void dfs(ll node, ll cstate)
{
    state[node] = cstate;
    ans[state[node]].push_back(node);
    visited[node] = true;
    for (auto c : g[node])
    {
        if (visited[c] == true && state[c] == state[node])
        {
            exists = false;
        }
        else if (!visited[c])
        {
            dfs(c, 1 - cstate);
        }
    }
}

int main()
{
    ll n, m;
    cin >> n >> m;
    ll a, b;
    for (int x = 0; x < m; x++)
    {
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    for (int x = 1; x <= n; x++)
    {
        if (visited[x] == false && g[x].size() != 0)
            dfs(b, 1);
    }
    if (!exists)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << ans[0].size() << endl;
        for (auto x : ans[0])
        {
            cout << x << " ";
        }
        cout << endl;
        cout << ans[1].size() << endl;
        for (auto x : ans[1])
        {
            cout << x << " ";
        }
        cout << endl;
    }
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll MAX = 1e5 + 5;
vector<ll> ans[2];
bool visited[MAX];
ll state[MAX];
ll exists = true;
vector<ll> g[MAX];

void dfs(ll node, ll cstate)
{
    state[node] = cstate;
    ans[state[node]].push_back(node);
    visited[node] = true;
    for (auto c : g[node])
    {
        if (visited[c] == true && state[c] == state[node])
        {
            exists = false;
        }
        else if (!visited[c])
        {
            dfs(c, 1 - cstate);
        }
    }
}

int main()
{
    ll n, m;
    cin >> n >> m;
    ll a, b;
    for (int x = 0; x < m; x++)
    {
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(a, 1);
    if (!exists)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << ans[0].size() << endl;
        for (auto x : ans[0])
        {
            cout << x << " ";
        }
        cout << endl;
        cout << ans[1].size() << endl;
        for (auto x : ans[1])
        {
            cout << x << " ";
        }
        cout << endl;
    }
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll MAX = 1e6 + 5;
vector<ll> ans[2];
bool visited[MAX];
ll state[MAX];
ll exists = true;
vector<ll> g[MAX];

bool dfs(ll node, ll cstate)
{
    state[node] = cstate;
    ans[state[node]].push_back(node);
    visited[node] = true;
    bool ret = true;
    for (auto c : g[node])
    {
        if (visited[c] == true && state[c] == state[node])
        {
            return false;
        }
        else if (!visited[c])
        {
            ret = ret && dfs(c, 1 - cstate);
        }
    }
    return ret;
}

int main()
{
    for (int x = 0; x < MAX; x++)
    {
        visited[x] = false;
    }
    ll n, m;
    cin >> n >> m;
    ll a, b;
    ll mm[m];
    for (int x = 0; x < m; x++)
    {
        cin >> a >> b;
        mm[x] = a;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    exists = true;
    for (int x = 1; x <= n; x++)
    {
        if (visited[x] == false && g[x].size() != 0)
            exists = exists && dfs(x, 0);
    }
    if (!exists)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << ans[0].size() << endl;
        for (auto x : ans[0])
        {
            cout << x << " ";
        }
        cout << endl;
        cout << ans[1].size() << endl;
        for (auto x : ans[1])
        {
            cout << x << " ";
        }
        cout << endl;
    }
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll MAX = 1e6 + 5;
vector<ll> ans[2];
bool visited[MAX];
ll state[MAX];
ll exists = true;
vector<ll> g[MAX];

void dfs(ll node, ll cstate)
{
    state[node] = cstate;
    ans[state[node]].push_back(node);
    visited[node] = true;
    for (auto c : g[node])
    {
        if (visited[c] == true && state[c] == state[node])
        {
            exists = false;
        }
        else if (!visited[c])
        {
            dfs(c, 1 - cstate);
        }
    }
}

int main()
{
    ll n, m;
    cin >> n >> m;
    ll a, b;
    for (int x = 0; x < m; x++)
    {
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(a, 1);
    if (!exists)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << ans[0].size() << endl;
        for (auto x : ans[0])
        {
            cout << x << " ";
        }
        cout << endl;
        cout << ans[1].size() << endl;
        for (auto x : ans[1])
        {
            cout << x << " ";
        }
        cout << endl;
    }
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll MAX = 1e6 + 5;
vector<ll> ans[2];
bool visited[MAX];
ll state[MAX];
// ll exists = true;
vector<ll> g[MAX];

bool dfs(ll node, ll cstate)
{
    state[node] = cstate;
    ans[state[node]].push_back(node);
    visited[node] = true;
    bool a = true;
    for (auto c : g[node])
    {
        if (visited[c] == true && state[c] == state[node])
        {
            // exists = false;
            a = a && false;
        }
        else if (!visited[c])
        {
            a = a && dfs(c, 1 - cstate);
        }
    }
    return a;
}

int main()
{
    ll n, m;
    cin >> n >> m;
    ll a, b;
    for (int x = 0; x < m; x++)
    {
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    bool exists = true;
    for (int x = 1; x <= n; x++)
    {
        if (visited[x] == false && g[x].size() != 0)
            exists = exists && dfs(b, 1);
    }
    if (!exists)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << ans[0].size() << endl;
        for (auto x : ans[0])
        {
            cout << x << " ";
        }
        cout << endl;
        cout << ans[1].size() << endl;
        for (auto x : ans[1])
        {
            cout << x << " ";
        }
        cout << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;

int n, m;
vector <int> E[maxn];
int vis[maxn] = {0};
set <int> ans1, ans2;
int flag = 0;
bool check[maxn] = {0};
int numcheck;

void dfs (int u, int f) {
//    cout << u << " " << " ?? " << f << "\n";
    vis[u] = f;
    if (f == 1) ans1.insert(u);
    else ans2.insert(u);
    for (int i = 0; i < E[u].size(); i++) {
        int v = E[u][i];
        if (vis[v] != 0) {
 //           cout << u << " " << v << " " << vis[u] << " " << vis[v] << "\n";
            if ((-1)*f != vis[v]) {
                flag = 1;
            }
        } else {
            dfs (v, (-1) * f);
        }
    }
}
void print() {
    cout << ans1.size() << "\n";
    for (int i : ans1) {
        cout << i << " ";
    }
    cout << "\n";
    cout << ans2.size() << "\n";
    for (int i : ans2) {
        cout << i << " ";
    }
}

void init() {
    flag = 0;
    ans1.clear();
    ans2.clear();
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    int cnt = 0;
    for (int i = 1; i <= m; i++) {
        int u, v; cin >> u >> v;
        E[u].push_back(v);
        E[v].push_back(u);
        if (!check[u]) {
            cnt++;
            check[u] = 1;
        }
        if (!check[v]) {
            cnt++;
            check[v] = 1;
        }
    }
//    if (n - cnt >= 2) {
//        int k = 0;
//        for (int i = 1; i <= n; i++) {
//            if (!check[i]) {
//                cout << "1\n";
//                cout << i << "\n";
//                k++;
//            }
//            if (k == 2) return 0;
//        }
//    }
//    if ((n - cnt) == 1) {
//        for (int i = 1; i <= n; i++) {
//            if (check[i]) {
//                numcheck = i;
//                break;
//            }
//        }
//    }
    for (int i = 1; i <= n; i++) {
        if (!check[i]) continue;
        if (vis[i] != 0) continue;
        init();
        dfs (i, 1);
//        if (flag && (n - cnt) == 1) {
//            cout << 1 << "\n";
//            cout << numcheck << "\n";
//            //ans1.size() +
//            cout <<  ans2.size() << "\n";
////            for (int i = 0; i < ans1.size(); i++) {
////                cout << ans1[i];
////                cout << " ";
////            }
//            for (int i = 0; i < ans2.size(); i++) {
//                cout << ans2[i];
//                if (ans2.size() == (i + 1)) cout << "\n";
//                else cout << " ";
//            }
//        }
        if (flag == 0) {
            print();
            return 0;
        }
    }
    cout << "-1\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;

int n, m;
vector <int> E[maxn];
int vis[maxn] = {0};
vector <int> ans1, ans2;
int flag = 0;
bool check[maxn] = {0};
int numcheck;

void dfs (int u, int f) {
//    cout << u << " " << " ?? " << f << "\n";
    vis[u] = f;
    if (f == 1) ans1.push_back(u);
    else ans2.push_back(u);
    for (int i = 0; i < E[u].size(); i++) {
        int v = E[u][i];
        if (vis[v] != 0) {
 //           cout << u << " " << v << " " << vis[u] << " " << vis[v] << "\n";
            if ((-1)*f != vis[v]) {
                flag = 1;
            }
        } else {
            dfs (v, (-1) * f);
        }
    }
}
void print() {
    cout << ans1.size() << "\n";
    for (int i = 0; i < ans1.size(); i++) {
        cout << ans1[i];
        if (ans1.size() == (i + 1)) cout << "\n";
        else cout << " ";
    }
    cout << ans2.size() << "\n";
    for (int i = 0; i < ans2.size(); i++) {
        cout << ans2[i];
        if (ans2.size() == (i + 1)) cout << "\n";
        else cout << " ";
    }
}

void init() {
    flag = 0;
    ans1.clear();
    ans2.clear();
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    int cnt = 0;
    for (int i = 1; i <= m; i++) {
        int u, v; cin >> u >> v;
        E[u].push_back(v);
        E[v].push_back(u);
        if (!check[u]) {
            cnt++;
            check[u] = 1;
        }
        if (!check[v]) {
            cnt++;
            check[v] = 1;
        }
    }
    if (n - cnt >= 2) {
        int k = 0;
        for (int i = 1; i <= n; i++) {
            if (!check[i]) {
                cout << "1\n";
                cout << i << "\n";
                k++;
            }
            if (k == 2) return 0;
        }
    }
//    if ((n - cnt) == 1) {
//        for (int i = 1; i <= n; i++) {
//            if (check[i]) {
//                numcheck = i;
//                break;
//            }
//        }
//    }
    for (int i = 1; i <= n; i++) {
        if (!check[i]) continue;
        if (vis[i] != 0) continue;
        init();
        dfs (i, 1);
//        if (flag && (n - cnt) == 1) {
//            cout << 1 << "\n";
//            cout << numcheck << "\n";
//            //ans1.size() +
//            cout <<  ans2.size() << "\n";
////            for (int i = 0; i < ans1.size(); i++) {
////                cout << ans1[i];
////                cout << " ";
////            }
//            for (int i = 0; i < ans2.size(); i++) {
//                cout << ans2[i];
//                if (ans2.size() == (i + 1)) cout << "\n";
//                else cout << " ";
//            }
//        }
        if (flag == 0) {
            print();
            return 0;
        }
    }
    cout << "-1\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;

int n, m;
vector <int> E[maxn];
int vis[maxn] = {0};
set <int> ans1, ans2;
int flag = 0;

void dfs (int u, int f) {
    vis[u] = f;
    if (f == 1) ans1.insert(u);
    else ans2.insert(u);
    for (int i = 0; i < E[u].size(); i++) {
        int v = E[u][i];
        if (vis[v] != 0) {
 //           cout << u << " " << v << " " << vis[u] << " " << vis[v] << "\n";
            if ((-1)*f != vis[v]) {
                flag = 1;
            }
        } else {
            dfs (v, (-1) * f);
        }
    }
}
void print() {
    cout << ans1.size() << "\n";
    for (int i : ans1) {
        cout << i << " ";
    }
    cout << "\n";
    cout << ans2.size() << "\n";
    for (int i : ans2) {
        cout << i << " ";
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    int cnt = 0;
    for (int i = 1; i <= m; i++) {
        int u, v; cin >> u >> v;
        E[u].push_back(v);
        E[v].push_back(u);
    }
    for (int i = 1; i <= n; i++) {
        if (vis[i] != 0) continue;
        dfs (i, 1);
    }
    if (flag == 0) {
        print();
    } else
        cout << "-1\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;

int n, m;
vector <int> E[maxn];
int vis[maxn] = {0};
vector <int> ans1, ans2;
int flag = 0;
bool check[maxn] = {0};
int numcheck;

void dfs (int u, int f) {
//    cout << u << " " << " ?? " << f << "\n";
    if (flag) return ;
    vis[u] = f;
    if (f == 1) ans1.push_back(u);
    else ans2.push_back(u);
    for (int i = 0; i < E[u].size(); i++) {
        int v = E[u][i];
        if (vis[v] != 0) {
 //           cout << u << " " << v << " " << vis[u] << " " << vis[v] << "\n";
            if ((-1)*f != vis[v]) {
                flag = 1;
                return ;
            }
        } else {
            dfs (v, (-1) * f);
        }
    }
}
void print() {
    cout << ans1.size() << "\n";
    for (int i = 0; i < ans1.size(); i++) {
        cout << ans1[i];
        if (ans1.size() == (i + 1)) cout << "\n";
        else cout << " ";
    }
    cout << ans2.size() << "\n";
    for (int i = 0; i < ans2.size(); i++) {
        cout << ans2[i];
        if (ans2.size() == (i + 1)) cout << "\n";
        else cout << " ";
    }
}

void init() {
    flag = 0;
    ans1.clear();
    ans2.clear();
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    int cnt = 0;
    for (int i = 1; i <= m; i++) {
        int u, v; cin >> u >> v;
        E[u].push_back(v);
        E[v].push_back(u);
        if (!check[u]) {
            cnt++;
            check[u] = 1;
        }
        if (!check[v]) {
            cnt++;
            check[v] = 1;
        }
    }
    if (n - cnt >= 2) {
        int k = 0;
        for (int i = 1; i <= n; i++) {
            if (!check[i]) {
                cout << "1\n";
                cout << i << "\n";
                k++;
            }
            if (k == 2) return 0;
        }
    }
    if ((n - cnt) == 1) {
        for (int i = 1; i <= n; i++) {
            if (check[i]) {
                numcheck = i;
                break;
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        if (!check[i]) continue;
        if (vis[i] != 0) continue;
        init();
        dfs (i, 1);
        if (flag && (n - cnt) == 1) {
            cout << 1 << "\n";
            cout << numcheck << "\n";
            //ans1.size() +
            cout <<  ans2.size() << "\n";
//            for (int i = 0; i < ans1.size(); i++) {
//                cout << ans1[i];
//                cout << " ";
//            }
            for (int i = 0; i < ans2.size(); i++) {
                cout << ans2[i];
                if (ans2.size() == (i + 1)) cout << "\n";
                else cout << " ";
            }
        }
        if (!flag) {
            print();
            return 0;
        }
    }
    cout << "-1\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;

int n, m;
vector <int> E[maxn];
int vis[maxn] = {0};
set <int> ans1, ans2;
int flag = 0;
bool check[maxn] = {0};
int numcheck;

void dfs (int u, int f) {
    vis[u] = f;
    if (f == 1) ans1.insert(u);
    else ans2.insert(u);
    for (int i = 0; i < E[u].size(); i++) {
        int v = E[u][i];
        if (vis[v] != 0) {
            if ((-1)*f != vis[v]) {
                flag = 1;
            }
        } else {
            dfs (v, (-1) * f);
        }
    }
}
void print() {
    cout << ans1.size() << "\n";
    for (int i : ans1) {
        cout << i << " ";
    }
    cout << "\n";
    cout << ans2.size() << "\n";
    for (int i : ans2) {
        cout << i << " ";
    }
}

void init() {
    flag = 0;
    ans1.clear();
    ans2.clear();
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    int cnt = 0;
    for (int i = 1; i <= m; i++) {
        int u, v; cin >> u >> v;
        E[u].push_back(v);
        E[v].push_back(u);
        if (!check[u]) {
            cnt++;
            check[u] = 1;
        }
        if (!check[v]) {
            cnt++;
            check[v] = 1;
        }
    }
    for (int i = 1; i <= n; i++) {
        if (!check[i]) continue;
        if (vis[i] != 0) continue;
        init();
        dfs (i, 1);
    }
    if (flag == 0) {
        print();
        return 0;
    }
    cout << "-1\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;

int n, m;
vector <int> E[maxn];
int vis[maxn] = {0};
vector <int> ans1, ans2;
int flag = 0;
bool check[maxn] = {0};
int numcheck;

void dfs (int u, int f) {
//    cout << u << " " << " ?? " << f << "\n";
    vis[u] = f;
    if (f == 1) ans1.push_back(u);
    else ans2.push_back(u);
    for (int i = 0; i < E[u].size(); i++) {
        int v = E[u][i];
        if (vis[v] != 0) {
 //           cout << u << " " << v << " " << vis[u] << " " << vis[v] << "\n";
            if ((-1)*f != vis[v]) {
                flag = 1;
            }
        } else {
            dfs (v, (-1) * f);
        }
    }
}
void print() {
    cout << ans1.size() << "\n";
    for (int i = 0; i < ans1.size(); i++) {
        cout << ans1[i];
        if (ans1.size() == (i + 1)) cout << "\n";
        else cout << " ";
    }
    cout << ans2.size() << "\n";
    for (int i = 0; i < ans2.size(); i++) {
        cout << ans2[i];
        if (ans2.size() == (i + 1)) cout << "\n";
        else cout << " ";
    }
}

void init() {
    flag = 0;
    ans1.clear();
    ans2.clear();
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    int cnt = 0;
    for (int i = 1; i <= m; i++) {
        int u, v; cin >> u >> v;
        E[u].push_back(v);
        E[v].push_back(u);
        if (!check[u]) {
            cnt++;
            check[u] = 1;
        }
        if (!check[v]) {
            cnt++;
            check[v] = 1;
        }
    }
//    if (n - cnt >= 2) {
//        int k = 0;
//        for (int i = 1; i <= n; i++) {
//            if (!check[i]) {
//                cout << "1\n";
//                cout << i << "\n";
//                k++;
//            }
//            if (k == 2) return 0;
//        }
//    }
//    if ((n - cnt) == 1) {
//        for (int i = 1; i <= n; i++) {
//            if (check[i]) {
//                numcheck = i;
//                break;
//            }
//        }
//    }
    for (int i = 1; i <= n; i++) {
        if (!check[i]) continue;
        if (vis[i] != 0) continue;
        init();
        dfs (i, 1);
//        if (flag && (n - cnt) == 1) {
//            cout << 1 << "\n";
//            cout << numcheck << "\n";
//            //ans1.size() +
//            cout <<  ans2.size() << "\n";
////            for (int i = 0; i < ans1.size(); i++) {
////                cout << ans1[i];
////                cout << " ";
////            }
//            for (int i = 0; i < ans2.size(); i++) {
//                cout << ans2[i];
//                if (ans2.size() == (i + 1)) cout << "\n";
//                else cout << " ";
//            }
//        }
        if (flag == 0) {
            print();
            return 0;
        }
    }
    cout << "-1\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;

int n, m;
vector <int> E[maxn];
int vis[maxn] = {0};
vector <int> ans1, ans2;
int flag = 0;
bool check[maxn] = {0};
int numcheck;

void dfs (int u, int f) {
//    cout << u << " " << " ?? " << f << "\n";
    vis[u] = f;
    if (f == 1) ans1.push_back(u);
    else ans2.push_back(u);
    for (int i = 0; i < E[u].size(); i++) {
        int v = E[u][i];
        if (vis[v] != 0) {
 //           cout << u << " " << v << " " << vis[u] << " " << vis[v] << "\n";
            if ((-1)*f != vis[v]) {
                flag = 1;
            }
        } else {
            dfs (v, (-1) * f);
        }
    }
}
void print() {
    cout << ans1.size() << "\n";
    for (int i = 0; i < ans1.size(); i++) {
        cout << ans1[i];
        if (ans1.size() == (i + 1)) cout << "\n";
        else cout << " ";
    }
    cout << ans2.size() << "\n";
    for (int i = 0; i < ans2.size(); i++) {
        cout << ans2[i];
        if (ans2.size() == (i + 1)) cout << "\n";
        else cout << " ";
    }
}

void init() {
    flag = 0;
    ans1.clear();
    ans2.clear();
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    int cnt = 0;
    for (int i = 1; i <= m; i++) {
        int u, v; cin >> u >> v;
        E[u].push_back(v);
        E[v].push_back(u);
        if (!check[u]) {
            cnt++;
            check[u] = 1;
        }
        if (!check[v]) {
            cnt++;
            check[v] = 1;
        }
    }
//    if (n - cnt >= 2) {
//        int k = 0;
//        for (int i = 1; i <= n; i++) {
//            if (!check[i]) {
//                cout << "1\n";
//                cout << i << "\n";
//                k++;
//            }
//            if (k == 2) return 0;
//        }
//    }
//    if ((n - cnt) == 1) {
//        for (int i = 1; i <= n; i++) {
//            if (check[i]) {
//                numcheck = i;
//                break;
//            }
//        }
//    }
    for (int i = 1; i <= n; i++) {
        if (!check[i]) continue;
        if (vis[i] != 0) continue;
        init();
        dfs (i, i);
//        if (flag && (n - cnt) == 1) {
//            cout << 1 << "\n";
//            cout << numcheck << "\n";
//            //ans1.size() +
//            cout <<  ans2.size() << "\n";
////            for (int i = 0; i < ans1.size(); i++) {
////                cout << ans1[i];
////                cout << " ";
////            }
//            for (int i = 0; i < ans2.size(); i++) {
//                cout << ans2[i];
//                if (ans2.size() == (i + 1)) cout << "\n";
//                else cout << " ";
//            }
//        }
        if (flag == 0) {
            print();
            return 0;
        }
    }
    cout << "-1\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

vector<vector<int> > v(100001);
vector<int> vis(100001);
vector<int> lvl(100001);
vector<int> col(100001);
vector<int> col1,col2;

int bfs(int s)
{
    queue<int> q;
    q.push(s);
    lvl[s]=0;
    col[s]=0;
    vis[s]=1;
    int f=0;

    while(!q.empty())
    {
        int p=q.front();
        q.pop();
        if(col[p]==1)col1.push_back(p);
        else if(col[p]==0)col2.push_back(p);
        for(int i=0;i<v[p].size();i++)
        {
            if(col[v[p][i]]==-1)
            {col[v[p][i]]=!col[p];lvl[v[p][i]]=lvl[p]+1;
            q.push(v[p][i]);}
            else
            {
                if(col[v[p][i]]==col[p])f=1;
            }
        }
    }
    if(f==1)return 0;
    return 1;

}

int main()
{
        int n,m;cin>>n>>m;
        fill(vis.begin(),vis.end(), 0);
        fill(col.begin(),col.end(), -1);
        fill(lvl.begin(),lvl.end(), 0);
        for(int i=0;i<v.size();i++)
        v[i].clear();
        for(int i=0;i<m;i++)
        {
            int x,y;cin>>x>>y;
            v[x].push_back(y);
            v[y].push_back(x);
        }
        int x=0;
        for(int i=1;i<=n;i++)
        {
            if(col[i]==-1&&v[i].size()>=1)x+=bfs(i);
        }
        if(x==0)cout<<-1;
        else
        {
            cout<<col1.size()<<endl;
            for(int i=0;i<col1.size();i++)
            cout<<col1[i]<<" ";
            cout<<endl;
            cout<<col2.size()<<endl;
            for(int i=0;i<col2.size();i++)
            cout<<col2[i]<<" ";
            cout<<endl;
        }
}


#include<bits/stdc++.h>
using namespace std;

vector<vector<int> > v(100001);
vector<int> vis(100001);
vector<int> par(100001);
vector<int> leafs;
vector<int> lc(100001);

int dfs(int src)
{
    stack<int> st;
    st.push(src);
    vis[src]=1;
    par[src]=-1;
    //cout<<src<<" ";
    while(!st.empty())
    {
        int x=st.top();
        st.pop();
        if(!vis[x])
        {vis[x]=1;}
        int f=0;
        for(int i=0;i<v[x].size();i++)
        {
            par[v[x][i]]=x;
            if(vis[v[x][i]]&&v[x][i]!=par[x])
            return 0;
            if(vis[v[x][i]]==0)
            {st.push(v[x][i]);f=1;}
        }
        if(f==0){leafs.push_back(x);lc[x]=1;}
    }
    return 1;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;cin>>n>>m;

    fill(vis.begin(),vis.end(), 0);
    for(int i=0;i<v.size();i++)
    v[i].clear();

    for(int i=0;i<m;i++)
    {
        int x,y;cin>>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    int x=dfs(1);
    if(x==0)
    cout<<-1<<endl;
    else
    {
        cout<<leafs.size()<<endl;
        for(int i=0;i<leafs.size();i++)
        cout<<leafs[i]<<" ";cout<<endl;
        vector<int> tmp;
        for(int i=1;i<=n;i++)
        {
            if(lc[i]==0)tmp.push_back(i);
        }
        cout<<tmp.size()<<endl;
        for(int i=0;i<tmp.size();i++)
        cout<<tmp[i]<<" ";
    }
}


#include<bits/stdc++.h>
using namespace std;

vector<vector<int> > v(100001);
vector<int> vis(100001);
vector<int> lvl(100001);
vector<int> col(100001);
vector<int> col1,col2;

int bfs(int s)
{
    queue<int> q;
    q.push(s);
    lvl[s]=0;
    col[s]=0;
    vis[s]=1;

    while(!q.empty())
    {
        int p=q.front();
        q.pop();
        if(col[p]==1)col1.push_back(p);
        else if(col[p]==0)col2.push_back(p);
        for(int i=0;i<v[p].size();i++)
        {
            if(col[v[p][i]]==-1)
            {col[v[p][i]]=!col[p];lvl[v[p][i]]=lvl[p]+1;
            q.push(v[p][i]);}
            else
            {
                if(col[v[p][i]]==col[p])return 0;
            }
        }
    }
    return 1;

}

int main()
{
        int n,m;cin>>n>>m;
        fill(vis.begin(),vis.end(), 0);
        fill(col.begin(),col.end(), -1);
        fill(lvl.begin(),lvl.end(), 0);
        for(int i=0;i<v.size();i++)
        v[i].clear();
        for(int i=0;i<m;i++)
        {
            int x,y;cin>>x>>y;
            v[x].push_back(y);
            v[y].push_back(x);
        }
        int x=0;
        for(int i=1;i<=n;i++)
        {
            if(col[i]==-1&&v[i].size()>=1)x+=bfs(i);
        }
        if(x==0)cout<<-1;
        else
        {
            cout<<col1.size()<<endl;
            for(int i=0;i<col1.size();i++)
            cout<<col1[i]<<" ";
            cout<<endl;
            cout<<col2.size()<<endl;
            for(int i=0;i<col2.size();i++)
            cout<<col2[i]<<" ";
            cout<<endl;
        }
}


#include<bits/stdc++.h>
using namespace std;

vector<vector<int> > v(100001);
vector<int> vis(100001);
vector<int> lvl(100001);
vector<int> col(100001);
vector<int> col1,col2;

int bfs(int s)
{
    queue<int> q;
    q.push(s);

    lvl[s]=0;
    col[s]=0;
    vis[s]=1;
    int f=0;
    if(v[s].size()==0)
    return 0;

    while(!q.empty())
    {
        int p=q.front();
        q.pop();
        if(col[p]==1)col1.push_back(p);
        else if(col[p]==0)col2.push_back(p);
        for(int i=0;i<v[p].size();i++)
        {
            if(col[v[p][i]]==-1)
            {col[v[p][i]]=!col[p];lvl[v[p][i]]=lvl[p]+1;
            q.push(v[p][i]);}
            else
            {
                if(col[v[p][i]]==col[p])f=1;
            }
        }
    }
    if(f==1)return -1;
    return 1;

}

int main()
{
        int n,m;cin>>n>>m;
        fill(vis.begin(),vis.end(), 0);
        fill(col.begin(),col.end(), -1);
        fill(lvl.begin(),lvl.end(), 0);
        for(int i=0;i<v.size();i++)
        v[i].clear();
        for(int i=0;i<m;i++)
        {
            int x,y;cin>>x>>y;
            v[x].push_back(y);
            v[y].push_back(x);
        }
        int x=1;
        for(int i=1;i<=n;i++)
        {
            int a;
            if(col[i]==-1)a=bfs(i);
            //cout<<i<<" "<<a<<endl;
            if(a==-1){x=0;break;}
        }
        if(x==0)cout<<-1;
        else
        {
            cout<<col1.size()<<endl;
            for(int i=0;i<col1.size();i++)
            cout<<col1[i]<<" ";
            cout<<endl;
            cout<<col2.size()<<endl;
            for(int i=0;i<col2.size();i++)
            cout<<col2[i]<<" ";
            cout<<endl;
        }
}


#include<bits/stdc++.h>
using namespace std;

vector<vector<int> > v(100001);
vector<int> vis(100001);
vector<int> lvl(100001);
vector<int> col(100001);
vector<int> col1,col2;

int bfs(int s)
{
    queue<int> q;
    q.push(s);
    lvl[s]=0;
    col[s]=0;
    vis[s]=1;

    while(!q.empty())
    {
        int p=q.front();
        q.pop();
        if(col[p]==1)col1.push_back(p);
        else if(col[p]==0)col2.push_back(p);
        for(int i=0;i<v[p].size();i++)
        {
            if(col[v[p][i]]==-1)
            {col[v[p][i]]=!col[p];lvl[v[p][i]]=lvl[p]+1;
            q.push(v[p][i]);}
            else
            {
                if(col[v[p][i]]==col[p])return 0;
            }
        }
    }
    return 1;

}

int main()
{
        int n,m;cin>>n>>m;
        fill(vis.begin(),vis.end(), 0);
        fill(col.begin(),col.end(), -1);
        fill(lvl.begin(),lvl.end(), 0);
        for(int i=0;i<v.size();i++)
        v[i].clear();
        for(int i=0;i<m;i++)
        {
            int x,y;cin>>x>>y;
            v[x].push_back(y);
            v[y].push_back(x);
        }
        int x=bfs(1);
        if(x==0)cout<<-1;
        else
        {
            cout<<col1.size()<<endl;
            for(int i=0;i<col1.size();i++)
            cout<<col1[i]<<" ";
            cout<<endl;
            cout<<col2.size()<<endl;
            for(int i=0;i<col2.size();i++)
            cout<<col2[i]<<" ";
            cout<<endl;
        }
}


#include<bits/stdc++.h>
using namespace std;

vector<vector<int> > v(100001);
vector<int> vis(100001);
vector<int> lvl(100001);
vector<int> col(100001);
vector<int> col1,col2;

int bfs(int s)
{
    queue<int> q;
    q.push(s);
    lvl[s]=0;
    col[s]=0;
    vis[s]=1;
    int f=0;

    while(!q.empty())
    {
        int p=q.front();
        q.pop();
        if(col[p]==1)col1.push_back(p);
        else if(col[p]==0)col2.push_back(p);
        for(int i=0;i<v[p].size();i++)
        {
            if(col[v[p][i]]==-1)
            {col[v[p][i]]=!col[p];lvl[v[p][i]]=lvl[p]+1;
            q.push(v[p][i]);}
            else
            {
                if(col[v[p][i]]==col[p])f=1;
            }
        }
    }
    if(f==1)return 0;
    return 1;

}

int main()
{
        int n,m;cin>>n>>m;
        fill(vis.begin(),vis.end(), 0);
        fill(col.begin(),col.end(), -1);
        fill(lvl.begin(),lvl.end(), 0);
        for(int i=0;i<v.size();i++)
        v[i].clear();
        for(int i=0;i<m;i++)
        {
            int x,y;cin>>x>>y;
            v[x].push_back(y);
            v[y].push_back(x);
        }
        int x;
        for(int i=1;i<=n;i++)
        {
            int a;
            if(col[i]==-1&&v[i].size()>=1)a=bfs(i);
            if(a==0){x=0;break;}
        }
        if(x==0)cout<<-1;
        else
        {
            cout<<col1.size()<<endl;
            for(int i=0;i<col1.size();i++)
            cout<<col1[i]<<" ";
            cout<<endl;
            cout<<col2.size()<<endl;
            for(int i=0;i<col2.size();i++)
            cout<<col2[i]<<" ";
            cout<<endl;
        }
}


#include<bits/stdc++.h>
using namespace std;

vector<vector<int> > v(100001);
vector<int> vis(100001);
vector<int> par(100001);
vector<int> leafs;
vector<int> lc(100001);

int dfs(int src)
{
    stack<int> st;
    st.push(src);
    if(v[src].size()==1){leafs.push_back(src);lc[src]=1;}
    vis[src]=1;
    par[src]=-1;
    //cout<<src<<" ";
    while(!st.empty())
    {
        int x=st.top();
        st.pop();
        if(!vis[x])
        {vis[x]=1;}
        int f=0;
        for(int i=0;i<v[x].size();i++)
        {
            par[v[x][i]]=x;
            if(vis[v[x][i]]&&v[x][i]!=par[x])
            return 0;
            if(vis[v[x][i]]==0)
            {st.push(v[x][i]);f=1;}
        }
        if(f==0){leafs.push_back(x);lc[x]=1;}
    }
    return 1;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;cin>>n>>m;

    fill(vis.begin(),vis.end(), 0);
    for(int i=0;i<v.size();i++)
    v[i].clear();
    map<int,int> mp;
    for(int i=0;i<m;i++)
    {
        int x,y;cin>>x>>y;
        mp[x]++;mp[y]++;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    int x=dfs(1);
    if(x==0)
    cout<<-1<<endl;
    else
    {
        vector<int> tmp;
        for(int i=1;i<=n;i++)
        {
            if(lc[i]==0&&mp[i]!=0)tmp.push_back(i);
        }
        cout<<tmp.size()<<endl;
        for(int i=0;i<tmp.size();i++)
        cout<<tmp[i]<<" ";
        cout<<endl;
        cout<<leafs.size()<<endl;
        for(int i=0;i<leafs.size();i++)
        cout<<leafs[i]<<" ";cout<<endl;
    }
}


#include<bits/stdc++.h>
#include<string>
#define FIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ll long long
#define mod (ll)(1e9+7)
#define nax (ll)(1e6)
#define INFL LLONG_MAX
#define NINFL LLONG_MIN
#define INF INT_MAX
#define disp(a,n,arr) for(int i=a;i<(ll)n;i++) cout << arr[i] << " "; cout << "\n";
#define check cout << "Working\n";
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vpl vector<pl>
#define vpi vector<pi>
#define vb vector<bool>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a) a.begin(),a.end()
using namespace std;

int main() {
	FIO;
	int t = 1;
	//cin >> t;
	while (t--) {
		ll n,m;
		cin >> n >> m;
		vl adj[n+1];
		for(int i=0;i<m;i++){
			ll u,v;
			cin >> u >> v;
			adj[u].pb(v);
			adj[v].pb(u);
		}

		vl color(n+1,-1);
		vb visited(n+1,false);
		vl one;
		vl zero;
		queue<ll> q;
		q.push(1);
		color[1] = 0;
		zero.pb(1);
		visited[1] = true;
		bool ans = true;
		while(!q.empty()){
			ll cur = q.back();
			q.pop();
			ll cur_color = color[cur];
			for(auto u:adj[cur]){
				if(color[u] == cur_color){
					ans = false;
					break;
				}
				if(!visited[u]){
					visited[u] = true;
					if(cur_color == 1) color[u] = 0,zero.pb(u);
					else color[u] = 1, one.pb(u);
					q.push(u);
 				}
			}
		}
		if(ans){
			cout << one.size() << "\n";
			disp(0,one.size(),one);
			cout << zero.size() << "\n";
			disp(0,zero.size(),zero);
		}else cout << "-1\n";
	}

	return 0;
}


#include<bits/stdc++.h>
#include<string>
#define FIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ll long long
#define mod (ll)(1e9+7)
#define nax (ll)(1e6)
#define INFL LLONG_MAX
#define NINFL LLONG_MIN
#define INF INT_MAX
#define disp(a,n,arr) for(int i=a;i<(ll)n;i++) cout << arr[i] << " "; cout << "\n";
#define check cout << "Working\n";
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vpl vector<pl>
#define vpi vector<pi>
#define vb vector<bool>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a) a.begin(),a.end()
using namespace std;

int main() {
	FIO;
	int t = 1;
	//cin >> t;
	while (t--) {
		ll n,m;
		cin >> n >> m;
		vl adj[n+1];
		for(int i=0;i<m;i++){
			ll u,v;
			cin >> u >> v;
			adj[u].pb(v);
			adj[v].pb(u);
		}

		vb vis(n+1,false);
		queue<ll> q;
		q.push(1);
		vl res[2];
		vl color(n+1,-1);
		color[1] = 1;
		res[1].pb(1);

		bool ans = true;
		while(!q.empty()){
			ll v = q.front();
			q.pop();
			for(auto u:adj[v]){
				if(color[u] == -1){
					color[u] = 1 - color[v];
					res[color[u]].pb(u);
					q.push(u);
				}
				else if(color[u] == color[v]){
					ans = false;
				}
			}
		}

		if(ans){
			cout << res[0].size() << "\n";
			disp(0,res[0].size(),res[0]);
			cout << res[1].size() << "\n";
			disp(0,res[1].size(),res[1]);
		}else cout << "-1\n";

	}

	return 0;
}


#include<bits/stdc++.h>
#include<string>
#define FIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ll long long
#define mod (ll)(1e9+7)
#define nax (ll)(1e6)
#define INFL LLONG_MAX
#define NINFL LLONG_MIN
#define INF INT_MAX
#define disp(a,n,arr) for(int i=a;i<(ll)n;i++) cout << arr[i] << " "; cout << "\n";
#define check cout << "Working\n";
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vpl vector<pl>
#define vpi vector<pi>
#define vb vector<bool>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a) a.begin(),a.end()
using namespace std;

int main() {
	FIO;
	int t = 1;
	//cin >> t;
	while (t--) {
		ll n,m;
		cin >> n >> m;
		vl adj[n+1];
		for(int i=0;i<m;i++){
			ll u,v;
			cin >> u >> v;
			adj[u].pb(v);
			adj[v].pb(u);
		}

		vl color(n+1,-1);
		vb visited(n+1,false);
		vl one;
		vl zero;
		queue<ll> q;
		q.push(1);
		color[1] = 0;
		zero.pb(1);
		visited[1] = true;
		bool ans = true;
		while(!q.empty()){
			ll cur = q.back();
			q.pop();
			ll cur_color = color[cur];
			for(auto u:adj[cur]){
				if(color[u] == cur_color){
					ans = false;
					break;
				}
				if(!visited[u]){
					visited[u] = true;
					if(cur_color == 1) color[u] = 0,zero.pb(u);
					else color[u] = 1, one.pb(u);
					q.push(u);
 				}
			}
		}
		if(ans){
			for(int i=1;i<=n;i++){
				if(!visited[i]){
					if(color[adj[i][0]] == 0) one.pb(i);
					else zero.pb(i);
				}
			}
		}
		if(ans){
			cout << one.size() << "\n";
			disp(0,one.size(),one);
			cout << zero.size() << "\n";
			disp(0,zero.size(),zero);
		}else cout << "-1\n";
	}

	return 0;
}


#include<bits/stdc++.h>
#include<string>
#define FIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ll long long
#define mod (ll)(1e9+7)
#define nax (ll)(1e6)
#define INFL LLONG_MAX
#define NINFL LLONG_MIN
#define INF INT_MAX
#define disp(a,n,arr) for(int i=a;i<(ll)n;i++) cout << arr[i] << " "; cout << "\n";
#define check cout << "Working\n";
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vpl vector<pl>
#define vpi vector<pi>
#define vb vector<bool>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a) a.begin(),a.end()
using namespace std;

vl adj[nax+1];
vl res[2];
vl color(nax+1,-1);

bool bfs(ll src){
		queue<ll> q;
		q.push(src);
		color[src] = 1;
		res[src].pb(1);
		bool ans = true;
		while(!q.empty()){
			ll v = q.front();
			q.pop();
			for(auto u:adj[v]){
				if(color[u] == -1){
					color[u] = 1 - color[v];
					res[color[u]].pb(u);
					q.push(u);
				}
				else if(color[u] == color[v]){
					ans = false;
				}
			}
		}
		return ans;
}

int main() {
	FIO;
	int t = 1;
	//cin >> t;
	while (t--) {
		ll n,m;
		cin >> n >> m;

		for(int i=0;i<m;i++){
			ll u,v;
			cin >> u >> v;
			adj[u].pb(v);
			adj[v].pb(u);
		}

		bool ans = true;
		for(int i=1;i<=n;i++){
			if(color[i] == -1){
				ans = bfs(i);
				if(!ans) break;
			}
		}

		if(ans){
			cout << res[0].size() << "\n";
			disp(0,res[0].size(),res[0]);
			cout << res[1].size() << "\n";
			disp(0,res[1].size(),res[1]);
		}else cout << "-1\n";

	}

	return 0;
}


#include<bits/stdc++.h>
#include<string>
#define FIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ll long long
#define mod (ll)(1e9+7)
#define nax (ll)(1e6)
#define INFL LLONG_MAX
#define NINFL LLONG_MIN
#define INF INT_MAX
#define disp(a,n,arr) for(int i=a;i<(ll)n;i++) cout << arr[i] << " "; cout << "\n";
#define check cout << "Working\n";
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vpl vector<pl>
#define vpi vector<pi>
#define vb vector<bool>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a) a.begin(),a.end()
using namespace std;

int main() {
	FIO;
	int t = 1;
	//cin >> t;
	while (t--) {
		ll n,m;
		cin >> n >> m;
		vl adj[n+1];
		for(int i=0;i<m;i++){
			ll u,v;
			cin >> u >> v;
			adj[u].pb(v);
			adj[v].pb(u);
		}

		vl color(n+1,-1);
		vb visited(n+1,false);
		vl one;
		vl zero;
		queue<ll> q;
		q.push(1);
		color[1] = 0;
		zero.pb(1);
		visited[1] = true;
		bool ans = true;
		while(!q.empty()){
			ll cur = q.back();
			q.pop();
			ll cur_color = color[cur];
			for(auto u:adj[cur]){
				if(color[u] == cur_color){
					ans = false;
					break;
				}
				if(!visited[u]){
					visited[u] = true;
					if(cur_color == 1) color[u] = 0,zero.pb(u);
					else color[u] = 1, one.pb(u);
					q.push(u);
 				}
			}
		}
		if(ans){
			for(int i=1;i<=n;i++){
				if(!visited[i] && !adj[i].empty()){
					if(color[adj[i][0]] == 0) one.pb(i);
					else zero.pb(i);
				}
			}
		}
		if(ans){
			cout << one.size() << "\n";
			disp(0,one.size(),one);
			cout << zero.size() << "\n";
			disp(0,zero.size(),zero);
		}else cout << "-1\n";
	}

	return 0;
}


#include<bits/stdc++.h>
#include<string>
#define FIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ll long long
#define mod (ll)(1e9+7)
#define nax (ll)(1e5+10)
#define INFL LLONG_MAX
#define NINFL LLONG_MIN
#define INF INT_MAX
#define disp(a,n,arr) for(int i=a;i<(ll)n;i++) cout << arr[i] << " "; cout << "\n";
#define check cout << "Working\n";
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vpl vector<pl>
#define vpi vector<pi>
#define vb vector<bool>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a) a.begin(),a.end()
using namespace std;

vl adj[nax+1];
vl res[2];
vl color(nax+1,-1);

bool bfs(ll src){
		queue<ll> q;
		q.push(src);
		color[src] = 1;
		res[color[src]].pb(1);
		bool ans = true;
		while(!q.empty()){
			ll v = q.front();
			q.pop();
			for(auto u:adj[v]){
				if(color[u] == -1){
					color[u] = 1 - color[v];
					res[color[u]].pb(u);
					q.push(u);
				}
				else if(color[u] == color[v]){
					ans = false;
				}
			}
		}
		return ans;
}

int main() {
	FIO;
	int t = 1;
	//cin >> t;
	while (t--) {
		ll n,m;
		cin >> n >> m;

		for(int i=0;i<m;i++){
			ll u,v;
			cin >> u >> v;
			adj[u].pb(v);
			adj[v].pb(u);
		}

		bool ans = true;
		for(int i=1;i<=n;i++){
			if(color[i] == -1){
				ans = bfs(i);
				if(!ans) break;
			}
		}

		if(ans){
			cout << res[0].size() << "\n";
			disp(0,res[0].size(),res[0]);
			cout << res[1].size() << "\n";
			disp(0,res[1].size(),res[1]);
		}else cout << "-1\n";

	}

	return 0;
}


#include<bits/stdc++.h>
#include<string>
#define FIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ll long long
#define mod (ll)(1e9+7)
#define nax (ll)(1e6)
#define INFL LLONG_MAX
#define NINFL LLONG_MIN
#define INF INT_MAX
#define disp(a,n,arr) for(int i=a;i<(ll)n;i++) cout << arr[i] << " "; cout << "\n";
#define check cout << "Working\n";
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vpl vector<pl>
#define vpi vector<pi>
#define vb vector<bool>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a) a.begin(),a.end()
using namespace std;

int main() {
	FIO;
	int t = 1;
	//cin >> t;
	while (t--) {
		ll n,m;
		cin >> n >> m;
		vl adj[n+1];
		for(int i=0;i<m;i++){
			ll u,v;
			cin >> u >> v;
			adj[u].pb(v);
			adj[v].pb(u);
		}

		vl color(n+1,-1);
		vb visited(n+1,false);
		vl one;
		vl zero;
		queue<ll> q;
		q.push(1);
		color[1] = 0;
		zero.pb(1);
		visited[1] = true;
		bool ans = true;
		while(!q.empty()){
			ll cur = q.front();
			q.pop();
			ll cur_color = color[cur];
			for(auto u:adj[cur]){
				if(color[u] == cur_color){
					ans = false;
					break;
				}
				if(!visited[u]){
					visited[u] = true;
					if(cur_color == 1) color[u] = 0,zero.pb(u);
					else color[u] = 1, one.pb(u);
					q.push(u);
 				}
			}
		}
		if(ans){
			for(int i=1;i<=n;i++){
				if(!visited[i] && !adj[i].empty()){
					if(color[adj[i][0]] == 0) one.pb(i);
					else zero.pb(i);
				}
			}
		}
		if(ans){
			cout << one.size() << "\n";
			disp(0,one.size(),one);
			cout << zero.size() << "\n";
			disp(0,zero.size(),zero);
		}else cout << "-1\n";
	}

	return 0;
}


#include<bits/stdc++.h>
#include<string>
#define FIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ll long long
#define mod (ll)(1e9+7)
#define nax (ll)(1e5+10)
#define INFL LLONG_MAX
#define NINFL LLONG_MIN
#define INF INT_MAX
#define disp(a,n,arr) for(int i=a;i<(ll)n;i++) cout << arr[i] << " "; cout << "\n";
#define check cout << "Working\n";
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vpl vector<pl>
#define vpi vector<pi>
#define vb vector<bool>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a) a.begin(),a.end()
using namespace std;

vl adj[nax+1];
vl res[2];
vl color(nax+1,-1);

bool bfs(ll src){
		queue<ll> q;
		q.push(src);
		color[src] = 1;
		res[color[src]].pb(src);
		bool ans = true;
		while(!q.empty()){
			ll v = q.front();
			q.pop();
			for(auto u:adj[v]){
				if(color[u] == -1){
					color[u] = 1 - color[v];
					res[color[u]].pb(u);
					q.push(u);
				}
				else if(color[u] == color[v]){
					ans = false;
				}
			}
		}
		return ans;
}

int main() {
	FIO;
	int t = 1;
	//cin >> t;
	while (t--) {
		ll n,m;
		cin >> n >> m;

		for(int i=0;i<m;i++){
			ll u,v;
			cin >> u >> v;
			adj[u].pb(v);
			adj[v].pb(u);
		}

		bool ans = true;
		for(int i=1;i<=n;i++){
			if(color[i] == -1){
				ans = bfs(i);
				if(!ans) break;
			}
		}

		if(ans){
			cout << res[0].size() << "\n";
			disp(0,res[0].size(),res[0]);
			cout << res[1].size() << "\n";
			disp(0,res[1].size(),res[1]);
		}else cout << "-1\n";

	}

	return 0;
}


#include <bits/stdc++.h>
//For ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define MOD 1000000007
#define test int t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define loop(i,a,b) for(int i=a;i<b;i++)
#define loopr(i,a,b) for(int i=a;i>=b;i--)
#define loops(i,a,b,step) for(int i=a;i<b;i+=step)
#define looprs(i,a,b,step) for(int i=a;i>=b;i-=step)
#define ull unsigned long long int
#define ll long long int
#define P pair
#define PLL pair<long long, long long>
#define PII pair<int, int>
#define PUU pair<unsigned long long int, unsigned long long int>
#define L list
#define V vector
#define D deque
#define ST set
#define MS multiset
#define M map
#define UM unordered_map
#define mp make_pair
#define pb push_back
#define pf push_front
#define MM multimap
#define F first
#define S second
#define IT iterator
#define RIT reverse_iterator
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define all(a) a.begin(),a.end()
#define ld long double
using namespace std;
// For ordered_set
using namespace __gnu_pbds;
template <typename T>
using ord_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll maxn = 1e5;
const ll inf = 1e9;
const double pi = acos(-1);

vector<int> type;
vector<bool> visited;
vector<vector<int>> adj;
vector<int> cp1,cp0;

bool dfs(int v,int t,int parent){
    visited[v]=true;
    type[v]=t;
    for(int u:adj[v]){
        if(!visited[u]){
            if(dfs(u,1-t,v)) continue;
            else return false;
        }
        else if(u!=parent) return type[v]!=type[u];
    }
    if(type[v]==1) cp1.pb(v+1);
    else cp0.pb(v+1);
    return true;
}
int main(){
   int n,m; cin>>n>>m;
   adj.resize(n); type.resize(n);
   visited.resize(n,false);
   for(int i=0;i<m;i++){
       int u,v; cin>>u>>v;
       adj[u-1].pb(v-1);
       adj[v-1].pb(u-1);
   }
    bool ok=false;
   for(int i=0;i<n;i++){
       if(!visited[i]&&dfs(i,0,-1)){
           if(cp0.size()>0&&cp1.size()>0){
                cout<<cp0.size()<<"\n";
                for(int x:cp0) cout<<x<<" ";
                cout<<"\n"<<cp1.size()<<"\n";
                for(int x:cp1) cout<<x<<" ";
                ok=true;
                break;
           }
       }
   }
    if(!ok) cout<<-1<<"\n";

   return 0;
}


#include <bits/stdc++.h>
//For ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define MOD 1000000007
#define test int t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define loop(i,a,b) for(int i=a;i<b;i++)
#define loopr(i,a,b) for(int i=a;i>=b;i--)
#define loops(i,a,b,step) for(int i=a;i<b;i+=step)
#define looprs(i,a,b,step) for(int i=a;i>=b;i-=step)
#define ull unsigned long long int
#define ll long long int
#define P pair
#define PLL pair<long long, long long>
#define PII pair<int, int>
#define PUU pair<unsigned long long int, unsigned long long int>
#define L list
#define V vector
#define D deque
#define ST set
#define MS multiset
#define M map
#define UM unordered_map
#define mp make_pair
#define pb push_back
#define pf push_front
#define MM multimap
#define F first
#define S second
#define IT iterator
#define RIT reverse_iterator
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define all(a) a.begin(),a.end()
#define ld long double
using namespace std;
// For ordered_set
using namespace __gnu_pbds;
template <typename T>
using ord_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll maxn = 1e5;
const ll inf = 1e9;
const double pi = acos(-1);

// unsolved problem ...

vector<int> type;
vector<bool> visited;
vector<vector<int>> adj;
vector<int> cp1,cp0;

bool dfs(int v,int t,int parent){
    visited[v]=true;

    type[v]=t;
    for(int u:adj[v]){
        if(!visited[u]){
            bool b=dfs(u,1-t,v);
            if(!b) return false;
        }
        else if(u!=parent){
            if(type[v]==type[u]) return false;
        }
    }
    if(type[v]==1) cp1.pb(v+1);
    else cp0.pb(v+1);
    return true;
}
int main(){
   int n,m; cin>>n>>m;
   adj.resize(n); type.resize(n);
   visited.resize(n,false);
   for(int i=0;i<m;i++){
       int u,v; cin>>u>>v;
       adj[u-1].pb(v-1);
       adj[v-1].pb(u-1);
   }

   for(int i=0;i<n;i++){
       if(!visited[i]){
           if(adj[i].empty()) continue;
           if(!dfs(i,0,-1)){
                cout<<-1<<"\n";
                return 0;
           }

       }
       // cp0.clear();
        // cp1.clear();
   }

    cout<<cp0.size()<<"\n";
    for(int x:cp0) cout<<x<<" ";
    cout<<"\n"<<cp1.size()<<"\n";
    for(int x:cp1) cout<<x<<" ";

   return 0;
}


#include <bits/stdc++.h>
//For ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define MOD 1000000007
#define test int t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define loop(i,a,b) for(int i=a;i<b;i++)
#define loopr(i,a,b) for(int i=a;i>=b;i--)
#define loops(i,a,b,step) for(int i=a;i<b;i+=step)
#define looprs(i,a,b,step) for(int i=a;i>=b;i-=step)
#define ull unsigned long long int
#define ll long long int
#define P pair
#define PLL pair<long long, long long>
#define PII pair<int, int>
#define PUU pair<unsigned long long int, unsigned long long int>
#define L list
#define V vector
#define D deque
#define ST set
#define MS multiset
#define M map
#define UM unordered_map
#define mp make_pair
#define pb push_back
#define pf push_front
#define MM multimap
#define F first
#define S second
#define IT iterator
#define RIT reverse_iterator
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define all(a) a.begin(),a.end()
#define ld long double
using namespace std;
// For ordered_set
using namespace __gnu_pbds;
template <typename T>
using ord_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll maxn = 1e5;
const ll inf = 1e9;
const double pi = acos(-1);

// unsolved problem ...

vector<int> type;
vector<bool> visited;
vector<vector<int>> adj;
vector<int> cp1,cp0;

bool dfs(int v,int t,int parent){
    visited[v]=true;

    type[v]=t;
    for(int u:adj[v]){
        if(!visited[u]){
            bool b=dfs(u,1-t,v);
            if(!b) return false;
        }
        else if(u!=parent){
            if(type[v]==type[u]) return false;
        }
    }
    if(type[v]==1) cp1.pb(v+1);
    else cp0.pb(v+1);
    return true;
}
int main(){
   int n,m; cin>>n>>m;
   adj.resize(n); type.resize(n);
   visited.resize(n,false);
   for(int i=0;i<m;i++){
       int u,v; cin>>u>>v;
       adj[u-1].pb(v-1);
       adj[v-1].pb(u-1);
   }

    bool ok=false;
   for(int i=0;i<n;i++){
       if(!visited[i]){
           if(adj[i].empty()) continue;
           if(dfs(i,0,-1)&&cp0.size()>0&&cp1.size()>0){
                cout<<cp0.size()<<"\n";
                for(int x:cp0) cout<<x<<" ";
                cout<<"\n"<<cp1.size()<<"\n";
                for(int x:cp1) cout<<x<<" ";
                ok=true;
                break;
           }

       }
        cp0.clear();
        cp1.clear();
   }
   if(!ok) cout<<-1<<"\n";

   return 0;
}


#include <bits/stdc++.h>
//For ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define MOD 1000000007
#define test int t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define loop(i,a,b) for(int i=a;i<b;i++)
#define loopr(i,a,b) for(int i=a;i>=b;i--)
#define loops(i,a,b,step) for(int i=a;i<b;i+=step)
#define looprs(i,a,b,step) for(int i=a;i>=b;i-=step)
#define ull unsigned long long int
#define ll long long int
#define P pair
#define PLL pair<long long, long long>
#define PII pair<int, int>
#define PUU pair<unsigned long long int, unsigned long long int>
#define L list
#define V vector
#define D deque
#define ST set
#define MS multiset
#define M map
#define UM unordered_map
#define mp make_pair
#define pb push_back
#define pf push_front
#define MM multimap
#define F first
#define S second
#define IT iterator
#define RIT reverse_iterator
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define all(a) a.begin(),a.end()
#define ld long double
using namespace std;
// For ordered_set
using namespace __gnu_pbds;
template <typename T>
using ord_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll maxn = 1e5;
const ll inf = 1e9;
const double pi = acos(-1);

vector<int> type;
vector<bool> visited;
vector<vector<int>> adj;
vector<int> cp1,cp0;

bool dfs(int v,int t,int parent){
    visited[v]=true;

    type[v]=t;
    for(int u:adj[v]){
        if(!visited[u]){
            bool b=dfs(u,1-t,v);
            if(!b) return false;
        }
        else if(u!=parent){
            if(type[v]==type[u]) return false;
        }
    }
    if(type[v]==1) cp1.pb(v+1);
    else cp0.pb(v+1);
    return true;
}
int main(){
   int n,m; cin>>n>>m;
   adj.resize(n); type.resize(n);
   visited.resize(n,false);
   for(int i=0;i<m;i++){
       int u,v; cin>>u>>v;
       adj[u-1].pb(v-1);
       adj[v-1].pb(u-1);
   }

    bool ok=false;
   for(int i=0;i<n;i++){
       if(!visited[i]&&dfs(i,0,-1)){
           if(cp0.size()>0&&cp1.size()>0){
                cout<<cp0.size()<<"\n";
                for(int x:cp0) cout<<x<<" ";
                cout<<"\n"<<cp1.size()<<"\n";
                for(int x:cp1) cout<<x<<" ";
                ok=true;
                break;
           }

       }
        cp0.clear();
        cp1.clear();
   }
   if(!ok) cout<<-1<<"\n";

   return 0;
}


#include <bits/stdc++.h>
//For ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define MOD 1000000007
#define test int t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define loop(i,a,b) for(int i=a;i<b;i++)
#define loopr(i,a,b) for(int i=a;i>=b;i--)
#define loops(i,a,b,step) for(int i=a;i<b;i+=step)
#define looprs(i,a,b,step) for(int i=a;i>=b;i-=step)
#define ull unsigned long long int
#define ll long long int
#define P pair
#define PLL pair<long long, long long>
#define PII pair<int, int>
#define PUU pair<unsigned long long int, unsigned long long int>
#define L list
#define V vector
#define D deque
#define ST set
#define MS multiset
#define M map
#define UM unordered_map
#define mp make_pair
#define pb push_back
#define pf push_front
#define MM multimap
#define F first
#define S second
#define IT iterator
#define RIT reverse_iterator
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define all(a) a.begin(),a.end()
#define ld long double
using namespace std;
// For ordered_set
using namespace __gnu_pbds;
template <typename T>
using ord_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll maxn = 1e5;
const ll inf = 1e9;
const double pi = acos(-1);

vector<int> type;
vector<bool> visited;
vector<vector<int>> adj;
vector<int> cp1,cp0;

bool dfs(int v,int t,int parent){
    visited[v]=true;
    type[v]=t;
    for(int u:adj[v]){
        if(!visited[u]){
            if(dfs(u,1-t,v)) continue;
            else return false;
        }
        else if(u!=parent) return type[v]!=type[u];
    }
    if(type[v]==1) cp1.pb(v+1);
    else cp0.pb(v+1);
    return true;
}
int main(){
   int n,m; cin>>n>>m;
   adj.resize(n); type.resize(n);
   visited.resize(n,false);
   for(int i=0;i<m;i++){
       int u,v; cin>>u>>v;
       adj[u-1].pb(v-1);
       adj[v-1].pb(u-1);
   }
    bool ok=false;
   for(int i=0;i<n;i++){
       if(!visited[i]&&dfs(i,0,-1)){
           if(cp0.size()>0&&cp1.size()>0){
                cout<<cp0.size()<<"\n";
                for(int x:cp0) cout<<x<<" ";
                cout<<"\n"<<cp1.size()<<"\n";
                for(int x:cp1) cout<<x<<" ";
                ok=true;
                break;
           }
       }
        cp0.clear();
        cp1.clear();
   }
    if(!ok) cout<<-1<<"\n";

   return 0;
}


#include <bits/stdc++.h>
//For ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define MOD 1000000007
#define test int t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define loop(i,a,b) for(int i=a;i<b;i++)
#define loopr(i,a,b) for(int i=a;i>=b;i--)
#define loops(i,a,b,step) for(int i=a;i<b;i+=step)
#define looprs(i,a,b,step) for(int i=a;i>=b;i-=step)
#define ull unsigned long long int
#define ll long long int
#define P pair
#define PLL pair<long long, long long>
#define PII pair<int, int>
#define PUU pair<unsigned long long int, unsigned long long int>
#define L list
#define V vector
#define D deque
#define ST set
#define MS multiset
#define M map
#define UM unordered_map
#define mp make_pair
#define pb push_back
#define pf push_front
#define MM multimap
#define F first
#define S second
#define IT iterator
#define RIT reverse_iterator
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define all(a) a.begin(),a.end()
#define ld long double
using namespace std;
// For ordered_set
using namespace __gnu_pbds;
template <typename T>
using ord_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll maxn = 1e5;
const ll inf = 1e9;
const double pi = acos(-1);

vector<int> type;
vector<bool> visited;
vector<vector<int>> adj;
vector<int> cp1,cp0;

bool dfs(int v,int t,int parent){
    visited[v]=true;
    type[v]=t;
    for(int u:adj[v]){
        if(!visited[u]){
            if(dfs(u,1-t,v)) continue;
            else return false;
        }
        else if(u!=parent) return type[v]!=type[u];
    }
    if(type[v]==1) cp1.pb(v+1);
    else cp0.pb(v+1);
    return true;
}
int main(){
   int n,m; cin>>n>>m;
   adj.resize(n); type.resize(n);
   visited.resize(n,false);
   for(int i=0;i<m;i++){
       int u,v; cin>>u>>v;
       adj[u-1].pb(v-1);
       adj[v-1].pb(u-1);
   }
    bool ok=false;
   for(int i=0;i<n;i++){
       if(!visited[i]&&dfs(i,0,-1)){
           cout<<cp0.size()<<"\n";
           for(int x:cp0) cout<<x<<" ";
           cout<<"\n"<<cp1.size()<<"\n";
           for(int x:cp1) cout<<x<<" ";
           ok=true;
           break;
       }
   }
    if(!ok) cout<<-1<<"\n";

   return 0;
}


#include <bits/stdc++.h>
#define fle(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define flt(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define fgt(i, a, b) for (int (i) = (a); (i) > (b); (i)--)
#define fge(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define log(var, sep) (cerr << #var << " = " << (var) << (sep))
#define pb push_back
#define nl (cout << endl)
#define pf first
#define ps second

using namespace std;

using ll = long long;
using ii = pair<ll, ll>;
using vi = vector<ll>;
using vp = vector< ii >;

const int MAX { 1000010 }; // 10^6 + 10
const ll oo { (1ll << 62) }; // 2^62
const ll MOD { 1000000007 }; // 10^9 + 7
const double PI = acos(-1.0); // 3.14
int n, m;
const int NONE = 0, BLUE = 1, RED = 2;
int color[MAX];
vi adj[MAX], half[2];
bool bfs(int s)
{
    queue<int> q;
    q.push(s);
    color[s] = BLUE;

    while (not q.empty())
    {
        auto u = q.front();
        q.pop();

        half[color[u]-1].pb(u);
        for (const auto& v : adj[u])
            if (color[v] == NONE)
            {
                color[v] = 3 - color[u];
                q.push(v);
            } else if (color[v] == color[u])
                return false;
    }

    return true;
}

bool is_bipartite(int N)
{
    for (int u = 1; u <= N; ++u)
        if (color[u] == NONE and not bfs(u))
            return false;

    return true;
}

int main () {
    cin >> n >> m;
    int x, y;
    flt (i, 0, m) {
        cin >> x >> y;
        adj[x].pb(y);
        adj[y].pb(x);
    }

    if (is_bipartite(n)) {
        cout << "1\n";
        for (auto & v : half[0]) printf("%lld%c", v, " \n"[v==half[0].back()]);
        cout << "2\n";
        for (auto & v : half[1]) printf("%lld%c", v, " \n"[v==half[1].back()]);
    } else {
        cout << -1 << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define fle(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define flt(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define fgt(i, a, b) for (int (i) = (a); (i) > (b); (i)--)
#define fge(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define log(var, sep) (cerr << #var << " = " << (var) << (sep))
#define pb push_back
#define nl (cout << endl)
#define pf first
#define ps second

using namespace std;

using ll = long long;
using ii = pair<ll, ll>;
using vi = vector<ll>;
using vp = vector< ii >;

const int MAX { 1000010 }; // 10^6 + 10
const ll oo { (1ll << 62) }; // 2^62
const ll MOD { 1000000007 }; // 10^9 + 7
const double PI = acos(-1.0); // 3.14
int n, m;
const int NONE = 0, BLUE = 1, RED = 2;
int color[MAX];
vi adj[MAX], half[2];
bool bfs(int s)
{
    queue<int> q;
    q.push(s);
    color[s] = BLUE;

    while (not q.empty())
    {
        auto u = q.front();
        q.pop();

        half[color[u]-1].pb(u);
        for (const auto& v : adj[u])
            if (color[v] == NONE)
            {
                color[v] = 3 - color[u];
                q.push(v);
            } else if (color[v] == color[u])
                return false;
    }

    return true;
}

bool is_bipartite(int N)
{
    for (int u = 1; u <= N; ++u)
        if (color[u] == NONE and not bfs(u))
            return false;

    return true;
}

int main () {
    cin >> n >> m;
    int x, y, maxi = 0;
    flt (i, 0, m) {
        cin >> x >> y;
        adj[x].pb(y);
        adj[y].pb(x);
        maxi = max(x, max(y, maxi));
    }

    if (is_bipartite(maxi)) {
        cout << "1\n";
        for (auto & v : half[0]) printf("%lld%c", v, " \n"[v==half[0].back()]);
        cout << "2\n";
        for (auto & v : half[1]) printf("%lld%c", v, " \n"[v==half[1].back()]);
    } else {
        cout << -1 << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define fle(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define flt(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define fgt(i, a, b) for (int (i) = (a); (i) > (b); (i)--)
#define fge(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define log(var, sep) (cerr << #var << " = " << (var) << (sep))
#define pb push_back
#define nl (cout << endl)

using namespace std;

using ll = long long;
using ii = pair<ll, ll>;
using vi = vector<ll>;
using vp = vector< ii >;

const int MAX { 1000010 }; // 10^6 + 10
const ll oo { (1 << 62) }; // 2^62
const ll MOD { 1000000007 }; // 10^9 + 7
const double PI = acos(-1.0); // 3.14

vi adj[MAX];
vi vc[2];
vp edges;

bool bipartite () {
	vi side(MAX, -1);
	queue<int> q;
	side[0] = 1;
	q.push(0);
	while (!q.empty()) {
		auto node = q.front();
		vc[side[node]].pb(node);
		q.pop();
		for (auto &neighbour : adj[node]) {
			if (side[neighbour] == -1) {
				side[neighbour] = 1 - side[node];
				q.push(neighbour);
			} else if (side[neighbour] == side[node]) {
				return false;
			}
		}
	}
	return true;
}

int main () {
	int n, m, u, v;

	cin >> n >> m;

	flt (i, 0, m) {
		cin >> u >> v;
		edges.pb({u-1, v-1});
	}

	for (const auto& [u, v] : edges) {
		adj[u].pb(v);
		adj[v].pb(u);
	}

	if (bipartite()) {
		flt (i, 0, 2) {
			cout << vc[i].size() << endl;
			for(int v : vc[i])
				cout << v + 1 << " ";
			cout << endl;
		}
	} else {
		cout << -1 << endl;
	}
	return 0;
}


#include <algorithm>
#include <iostream>

using namespace std;

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        int point = 0;
        int a[1001000];
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        int turn = 0;
        int current = 0;
        while (current < (n - 1)) {
            if (turn == 0) {
                if (a[current] == 0) {
                    if (a[current + 1] == 0) {
                        current += 2;
                    } else {
                        current++;
                    }
                } else {
                    point++;
                    if (a[current + 1] == 0) {
                        current += 2;
                    } else {
                        current++;
                    }
                }
            } else {
                if (a[current + 1] == 0) {
                    current++;
                } else {
                    current += 2;
                }
            }
            turn = 1 - turn;
        }
        if (current == (n -1) && turn == 0 && a[current] == 1) {
            point++;
        }
        cout << point << endl;
    }
    return 0;
}