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

vector<int> adj[100000+5];
vector<int> red;
vector<int> blue;
int color[100000+5];
bool isbipartite(int x){
	memset(color,-1,sizeof(color));
	queue<int> q;
	q.push(x);
	color[x]=1;
	blue.push_back(x);
	while(!q.empty()){
		int a=q.front();
		q.pop();
		for(int i=0;i<adj[a].size();i++){
			if(color[adj[a][i]]==-1){
				color[adj[a][i]]=1-color[a];
				q.push(adj[a][i]);
				if(color[adj[a][i]]==0){
					red.push_back(adj[a][i]);
				}
				else{
					blue.push_back(adj[a][i]);
				}
			}
			else if(color[adj[a][i]]==color[a])
			return false;
		}
	}
	return true;
}
int main(){
	int n,m;
	cin >> n >> m;
	for(int i=0;i<m;i++){
		int a,b;
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	bool temp=isbipartite(1);
	if(temp){
		vector<int> :: iterator it;
		cout << red.size() << endl;
		for(it=red.begin();it!=red.end();it++){
			cout << *it << " ";
		}
		cout << endl << blue.size() << endl;
		for(it=blue.begin();it!=blue.end();it++){
			cout << *it << " ";
		}
		cout << endl;
	}
	else{
		cout << -1 << endl;
	}
	return 0;
}


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

vector<int> adj[100000+5];
vector<int> red;
vector<int> blue;
int color[100000+5];
int visited[100000+5];
bool isbipartite(int x){
	memset(color,-1,sizeof(color));
	queue<int> q;
	q.push(x);
	color[x]=1;
	blue.push_back(x);
	while(!q.empty()){
		int a=q.front();
		q.pop();
		visited[a]=1;
		for(int i=0;i<adj[a].size();i++){
			if(color[adj[a][i]]==-1){
				color[adj[a][i]]=1-color[a];
				q.push(adj[a][i]);
				if(color[adj[a][i]]==0){
					red.push_back(adj[a][i]);
				}
				else{
					blue.push_back(adj[a][i]);
				}
			}
			else if(color[adj[a][i]]==color[a])
			return false;
		}
	}
	return true;
}
int main(){
	int n,m;
	cin >> n >> m;
	int t;
	for(int i=0;i<m;i++){
		int a,b;
		cin >> a >> b;
		if(i==0)
		t=a;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	bool temp=true;;
	memset(visited,0,sizeof(visited));
	for(int i=1;i<=n;i++){
		if(!visited[i] && adj[i].size()>0)
		temp=temp & isbipartite(i);
	}
	if(temp){
		vector<int> :: iterator it;
		cout << red.size() << endl;
		for(it=red.begin();it!=red.end();it++){
			cout << *it << " ";
		}
		cout << endl << blue.size() << endl;
		for(it=blue.begin();it!=blue.end();it++){
			cout << *it << " ";
		}
		cout << endl;
	}
	else{
		cout << -1 << endl;
	}
	return 0;
}


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

vector<int> adj[100000+5];
vector<int> red;
vector<int> blue;
int color[100000+5];
bool isbipartite(int x){
	memset(color,-1,sizeof(color));
	queue<int> q;
	q.push(x);
	color[x]=1;
	blue.push_back(x);
	while(!q.empty()){
		int a=q.front();
		q.pop();
		for(int i=0;i<adj[a].size();i++){
			if(color[adj[a][i]]==-1){
				color[adj[a][i]]=1-color[a];
				q.push(adj[a][i]);
				if(color[adj[a][i]]==0){
					red.push_back(adj[a][i]);
				}
				else{
					blue.push_back(adj[a][i]);
				}
			}
			else if(color[adj[a][i]]==color[a])
			return false;
		}
	}
	return true;
}
int main(){
	int n,m;
	cin >> n >> m;
	int t;
	for(int i=0;i<m;i++){
		int a,b;
		cin >> a >> b;
		if(i==0)
		t=a;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	bool temp=isbipartite(t);
	if(temp){
		vector<int> :: iterator it;
		cout << red.size() << endl;
		for(it=red.begin();it!=red.end();it++){
			cout << *it << " ";
		}
		cout << endl << blue.size() << endl;
		for(it=blue.begin();it!=blue.end();it++){
			cout << *it << " ";
		}
		cout << endl;
	}
	else{
		cout << -1 << endl;
	}
	return 0;
}


#include <cstdio>
#include <vector>
#include <cstring>
#include <queue>
using namespace std;
const int MAXN=100005;
int n,m,a,b,ansacnt,cnt=0,ans=1;
vector<int> graph[MAXN],ansa,ansb;
queue<int> q;
int color[MAXN];

void dfs(int st,int colorState)
{
        if(color[st]==-1)
        {
                color[st]=colorState;
        }
        else if(color[st]!=colorState)
        {
                ans=0;
                return;
        }
        else
        {
                return;
        }
        for(int i=0;i<graph[st].size();i++)
                dfs(graph[st][i],3-colorState);
}

int main()
{
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;i++)
                graph[i].clear();
        memset(color,-1,sizeof(color));
        while(m--)
        {
                scanf("%d%d",&a,&b);
                graph[a].push_back(b);
                graph[b].push_back(a);
        }
        for(int i=1;i<=n;i++)
        {
                if(color[i]==-1&&!graph[i].empty())
                       dfs(i,1);
        }
        if(ans==0)
        {
                printf("-1\n");
        }
        else
        {
                for(int i=1;i<=n;i++)
                {
                        if(color[i]==1)
                        {
                                cnt++;
                                ansa.push_back(i);
                        }
                        else
                        {
                                ansb.push_back(i);
                        }
                }
                printf("%d\n",cnt);
                for(int i=0;i<cnt;i++)
                        printf("%d%c",ansa[i],i==cnt-1?'\n':' ');
                printf("%d\n",n-cnt);
                for(int i=0;i<n-cnt;i++)
                        printf("%d%c",ansb[i],i==n-cnt-1?'\n':' ');
        }
        return 0;
}


#include <cstdio>
#include <vector>
#include <cstring>
#include <queue>
using namespace std;
const int MAXN=100005;
int n,m,a,b,ansacnt,cnt=0,ans=1;
vector<int> graph[MAXN],ansa,ansb;
queue<int> q;
int color[MAXN];

void dfs(int st,int colorState)
{
        if(color[st]==-1)
        {
                color[st]=colorState;
        }
        if(color[st]!=colorState)
        {
                ans=0;
                return;
        }
        else
        {
                return;
        }
        for(int i=0;i<graph[st].size();i++)
                dfs(graph[st][i],3-colorState);
}

int main()
{
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;i++)
                graph[i].clear();
        memset(color,-1,sizeof(color));
        while(m--)
        {
                scanf("%d%d",&a,&b);
                graph[a].push_back(b);
                graph[b].push_back(a);
        }
        for(int i=1;i<=n;i++)
        {
                if(color[i]==-1&&!graph[i].empty())
                       dfs(i,1);
        }
        for(int i=1;i<=n;i++)
        {
                if(color[i]==1)
                {
                        cnt++;
                        ansa.push_back(i);
                }
                else
                {
                        ansb.push_back(i);
                }
        }
        if(ans==0||cnt==n||cnt==0)
        {
                printf("-1\n");
        }
        else
        {
                printf("%d\n",cnt);
                for(int i=0;i<cnt;i++)
                        printf("%d%c",ansa[i],i==cnt-1?'\n':' ');
                printf("%d\n",n-cnt);
                for(int i=0;i<n-cnt;i++)
                        printf("%d%c",ansb[i],i==n-cnt-1?'\n':' ');
        }
        return 0;
}


#include <cstdio>
#include <vector>
#include <cstring>
#include <queue>
using namespace std;
const int MAXN=100005;
int n,m,a,b,ansacnt,cnt=0;
vector<int> graph[MAXN],ansa,ansb;
queue<int> q;
int color[MAXN];

int dfs(int st,int colorState=1)
{
        color[st]=colorState;
        for(int i=0;i<graph[st].size();i++)
        {
                int nxt=graph[st][i];
                if(color[nxt]==-1&&dfs(nxt,3-colorState))
                        return 0;
                if(color[nxt]==colorState)
                        return 0;
        }
        return 1;
}

int main()
{
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;i++)
                graph[i].clear();
        memset(color,-1,sizeof(color));
        while(m--)
        {
                scanf("%d%d",&a,&b);
                graph[a].push_back(b);
                graph[b].push_back(a);
        }
        int ans=1;
        for(int i=1;i<=n;i++)
        {
                if(color[i]==-1&&dfs(i)==0)
                {
                        ans=0;
                        break;
                }
        }
        if(ans==0)
        {
                printf("-1\n");
        }
        else
        {
                for(int i=1;i<=n;i++)
                {
                        if(color[i]==1)
                        {
                                cnt++;
                                ansa.push_back(i);
                        }
                        else
                        {
                                ansb.push_back(i);
                        }
                }
                printf("%d\n",cnt);
                for(int i=0;i<cnt;i++)
                        printf("%d%c",ansa[i],i==cnt-1?'\n':' ');
                printf("%d\n",n-cnt);
                for(int i=0;i<n-cnt;i++)
                        printf("%d%c",ansb[i],i==n-cnt-1?'\n':' ');
        }
        return 0;
}


#include <cstdio>
#include <vector>
#include <cstring>
#include <queue>
using namespace std;
const int MAXN=100005;
int n,m,a,b,ansacnt,cnt=0;
vector<int> graph[MAXN],ansa,ansb;
queue<int> q;
int color[MAXN];

int bfs(int st)
{
        while(!q.empty())
                q.pop();
        color[st]=1;
        q.push(st);
        while(!q.empty())
        {
                int fro=q.front();
                q.pop();
                for(int i=0;i<graph[fro].size();i++)
                {
                        int nxt=graph[fro][i];
                        if(nxt==fro)
                                continue;
                        if(color[nxt]==-1)
                        {
                                color[nxt]=3-color[fro];
                                q.push(nxt);
                        }
                        else
                        {
                                if(color[fro]==color[nxt])
                                        return 0;
                        }
                }
        }
        return 1;
}

int main()
{
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;i++)
                graph[i].clear();
        memset(color,-1,sizeof(color));
        while(m--)
        {
                scanf("%d%d",&a,&b);
                graph[a].push_back(b);
                graph[b].push_back(a);
        }
        int ans=1;
        for(int i=1;i<=n;i++)
        {
                if(color[i]==-1&&bfs(i)==0)
                {
                        ans=0;
                        break;
                }
        }
        if(ans==0)
        {
                printf("-1\n");
        }
        else
        {
                for(int i=1;i<=n;i++)
                {
                        if(color[i]==1)
                        {
                                cnt++;
                                ansa.push_back(i);
                        }
                        else
                        {
                                ansb.push_back(i);
                        }
                }
                printf("%d\n",cnt);
                for(int i=0;i<cnt;i++)
                        printf("%d%c",ansa[i],i==cnt-1?'\n':' ');
                printf("%d\n",n-cnt);
                for(int i=0;i<n-cnt;i++)
                        printf("%d%c",ansb[i],i==n-cnt-1?'\n':' ');
        }
        return 0;
}


#include<iostream>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<string.h>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include <queue>
#include<string>
#include<sstream>
#include<stack>
#include <iomanip>
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
#define rep(i,A,B) for(int i=A;i<=B;i++)
#define pb push_back
#define mp make_pair
#define S second
#define F first
#define all(c) (c).begin(), (c).end()
#define vectorIterate(v) for(auto it=v.begin(); it!=v.end();it++)
#define mod 1000000007

ll gcd(ll a, ll b)
{
   if (b==0) return a;
   return gcd(b,a%b);
}
ll lcm(ll a, ll b)
{
   return b*a/gcd(a,b);
}

ll abs1(ll a)
{
	if(a<0)
	return -1*a;
	else return a;
}
ll max(ll a,ll b)
{
	if(a>b)
	return a;
	return b;
}
ll fast_pow(long long base, long long n)
{
    if(n==0)
       return 1;
    if(n==1)
    return base;
    long long halfn=fast_pow(base,n/2);
    if(n%2==0)
        return ( halfn * halfn );
    else
        return ( ( ( halfn * halfn )  ) * base ) ;
}
ll findMMI_fermat(ll n,ll M)
{
    return fast_pow(n,M-2);
}
const double PI = 3.14159265358979323846;
vector<int> v[100001];
bool b[1000001];

map<ll,ll> ma;
//map<pair<int,int> ,int> pa;
int m,n;
vector<int> x[2];
int dfs(int i)
{

	int k=0;

	stack<pair<int,int> > s;
	s.push(mp(i,k));
	while(!s.empty())
	{
		pair<int,int> t=s.top();
		s.pop();
//		if(ma[t.F]!=0&&ma[t.F]!=t.S)
//		{
//			cout<<t.F<<" "<<t.S;
//			return -1;
//		}
		if(b[t.F]==false)
		{
			b[t.F]=true;
//			cout<<t.F<<" "<<t.S<<'\n';
			ma[t.F]=t.S+1;
			x[t.S].pb(t.F);
			t.S=(t.S+1)%2;

			for(int i=1;i<=n;i++)
			{
				if(v[t.F][i]==1)
	           s.push(mp(i,t.S));

			}

		}

	}

}

int main()
{

	memset(b,false,sizeof(b));
     //int m,n;
     //cout<<v[0][0];
     cin>>n>>m;
     for(int i=0;i<=n;i++)
     {
     	v[i].resize(100001);
	 }
     for(int i=0;i<m;i++)
     {
     	int x,y;
     	cin>>x>>y;
     	v[x][y]=1;
     	v[y][x]=1;
  //   	pa[mp(x,y)]=1;
    // 	pa[mp(y,x)]=1;
  //   	v[x].pb(y);
    // 	v[y].pb(x);

	 }
	 for(int i=1;i<=n;i++)
	 {
	 	if(b[i]==false)
	 	{
	 		dfs(i);//==-1)

		}
	 }
	 for(int i=0;i<x[0].size();i++ )
	 for(int j=i+1;j<x[0].size();j++)
	 {
	 	if(v[x[0][i]][x[0][j]]==1)
	 	{
	 		cout<<"-1";
	 		return 0;
		 }

	 }
	 	 for(int i=0;i<x[1].size();i++ )
	 for(int j=i+1;j<x[1].size();j++)
	 {
	 	if(v[x[1][i]][x[1][j]]==1)
	 	{
	 		cout<<"-1";
	 		return 0;
		 }

	 }

	 cout<<x[0].size()<<'\n';

	 for(int i=0;i<x[0].size();i++)
	 cout<<x[0][i]<<" ";

	 cout<<'\n';
	 cout<<x[1].size()<<'\n';

	 for(int i=0;i<x[1].size();i++)
	 cout<<x[1][i]<<" ";
     //map<int,int> ma,pa;
   //  vector<pair<int,int> > v;
     //set<int>c,d;

	return 0;
}


#include<iostream>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<string.h>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include <queue>
#include<string>
#include<sstream>
#include<stack>
#include <iomanip>
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
#define rep(i,A,B) for(int i=A;i<=B;i++)
#define pb push_back
#define mp make_pair
#define S second
#define F first
#define all(c) (c).begin(), (c).end()
#define vectorIterate(v) for(auto it=v.begin(); it!=v.end();it++)
#define mod 1000000007

ll gcd(ll a, ll b)
{
   if (b==0) return a;
   return gcd(b,a%b);
}
ll lcm(ll a, ll b)
{
   return b*a/gcd(a,b);
}

ll abs1(ll a)
{
	if(a<0)
	return -1*a;
	else return a;
}
ll max(ll a,ll b)
{
	if(a>b)
	return a;
	return b;
}
ll fast_pow(long long base, long long n)
{
    if(n==0)
       return 1;
    if(n==1)
    return base;
    long long halfn=fast_pow(base,n/2);
    if(n%2==0)
        return ( halfn * halfn );
    else
        return ( ( ( halfn * halfn )  ) * base ) ;
}
ll findMMI_fermat(ll n,ll M)
{
    return fast_pow(n,M-2);
}
const double PI = 3.14159265358979323846;
vector<int> v[100001];
bool b[100001];

//map<ll,ll> ma;
//map<pair<int,int> ,int> pa;
int m,n;
vector<int> x[2];
int dfs(int i)
{

	int k=0;

	stack<pair<int,int> > s;
	s.push(mp(i,k));
	while(!s.empty())
	{
		pair<int,int> t=s.top();
		s.pop();
//		if(ma[t.F]!=0&&ma[t.F]!=t.S)
//		{
//			cout<<t.F<<" "<<t.S;
//			return -1;
//		}
		if(b[t.F]==false)
		{
			b[t.F]=true;
//			cout<<t.F<<" "<<t.S<<'\n';
//			ma[t.F]=t.S+1;
			x[t.S].pb(t.F);
			t.S=(t.S+1)%2;

			for(int i=1;i<=n;i++)
			{
				if(v[t.F][i]==1)
	           s.push(mp(i,t.S));

			}

		}

	}

}

int main()
{

	memset(b,false,sizeof(b));
     //int m,n;
     //cout<<v[0][0];
     cin>>n>>m;
     for(int i=0;i<=n;i++)
     {
     	v[i].resize(100001);
	 }
     for(int i=0;i<m;i++)
     {
     	int x,y;
     	cin>>x>>y;
     	v[x][y]=1;
     	v[y][x]=1;
  //   	pa[mp(x,y)]=1;
    // 	pa[mp(y,x)]=1;
  //   	v[x].pb(y);
    // 	v[y].pb(x);

	 }
	 for(int i=1;i<=n;i++)
	 {
	 	if(b[i]==false)
	 	{
	 		dfs(i);//==-1)

		}
	 }
	 for(int i=0;i<x[0].size();i++ )
	 for(int j=i+1;j<x[0].size();j++)
	 {
	 	if(v[x[0][i]][x[0][j]]==1)
	 	{
	 		cout<<"-1";
	 		return 0;
		 }

	 }
	 	 for(int i=0;i<x[1].size();i++ )
	 for(int j=i+1;j<x[1].size();j++)
	 {
	 	if(v[x[1][i]][x[1][j]]==1)
	 	{
	 		cout<<"-1";
	 		return 0;
		 }

	 }

	 cout<<x[0].size()<<'\n';

	 for(int i=0;i<x[0].size();i++)
	 cout<<x[0][i]<<" ";

	 cout<<'\n';
	 cout<<x[1].size()<<'\n';

	 for(int i=0;i<x[1].size();i++)
	 cout<<x[1][i]<<" ";
     //map<int,int> ma,pa;
   //  vector<pair<int,int> > v;
     //set<int>c,d;

	return 0;
}


#include<iostream>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<string.h>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include <queue>
#include<string>
#include<sstream>
#include<stack>
#include <iomanip>
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
#define rep(i,A,B) for(int i=A;i<=B;i++)
#define pb push_back
#define mp make_pair
#define S second
#define F first
#define all(c) (c).begin(), (c).end()
#define vectorIterate(v) for(auto it=v.begin(); it!=v.end();it++)
#define mod 1000000007

ll gcd(ll a, ll b)
{
   if (b==0) return a;
   return gcd(b,a%b);
}
ll lcm(ll a, ll b)
{
   return b*a/gcd(a,b);
}

ll abs1(ll a)
{
	if(a<0)
	return -1*a;
	else return a;
}
ll max(ll a,ll b)
{
	if(a>b)
	return a;
	return b;
}
ll fast_pow(long long base, long long n)
{
    if(n==0)
       return 1;
    if(n==1)
    return base;
    long long halfn=fast_pow(base,n/2);
    if(n%2==0)
        return ( halfn * halfn );
    else
        return ( ( ( halfn * halfn )  ) * base ) ;
}
ll findMMI_fermat(ll n,ll M)
{
    return fast_pow(n,M-2);
}
const double PI = 3.14159265358979323846;

//map<ll,ll> ma;
int main()
{
     int m,n;
     cin>>n>>m;
     map<int,int> ma,pa;
     vector<pair<int,int> > v;
     set<int>c,d;
     while(m--)
     {
     	int x,y;
     	cin>>x>>y;
     	v.pb(mp(x,y));
     	if((ma[x]>0&&ma[y]>0)||(pa[x]>0&&ma[y]>0))
     	{
     		cout<<-1;
     		return 0;
		 }
		 else if((ma[x]>0&&pa[y]>0)||ma[x]>0||pa[y]>0)
		 {
		 	ma[x]++;
		 	pa[y]++;
		 	c.insert(x);
		 	d.insert(y);
		 }
		 else if((ma[y]>0&&pa[x]>0)||ma[y]>0||pa[x]>0)
		 {
		 	ma[y]++;
		 	pa[x]++;
		 	c.insert(y);
		 	d.insert(x);
		 }
		 else
		 {
		 	ma[x]++;
		 	pa[y]++;
		 	c.insert(x);
		 	d.insert(y);
		 }

	 }
	 cout<<c.size()<<'\n';
	 set<int>::iterator it;
	 for(it=c.begin();it!=c.end();it++)
	 {
	 	cout<<*it<<" ";
	 }
	 cout<<'\n';
	 cout<<d.size()<<'\n';
	  for(it=d.begin();it!=d.end();it++)
	 {
	 	cout<<*it<<" ";
	 }

	return 0;
}


#include<iostream>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<string.h>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include <queue>
#include<string>
#include<sstream>
#include<stack>
#include <iomanip>
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
#define rep(i,A,B) for(int i=A;i<=B;i++)
#define pb push_back
#define mp make_pair
#define S second
#define F first
#define all(c) (c).begin(), (c).end()
#define vectorIterate(v) for(auto it=v.begin(); it!=v.end();it++)
#define mod 1000000007

ll gcd(ll a, ll b)
{
   if (b==0) return a;
   return gcd(b,a%b);
}
ll lcm(ll a, ll b)
{
   return b*a/gcd(a,b);
}

ll abs1(ll a)
{
	if(a<0)
	return -1*a;
	else return a;
}
ll max(ll a,ll b)
{
	if(a>b)
	return a;
	return b;
}
ll fast_pow(long long base, long long n)
{
    if(n==0)
       return 1;
    if(n==1)
    return base;
    long long halfn=fast_pow(base,n/2);
    if(n%2==0)
        return ( halfn * halfn );
    else
        return ( ( ( halfn * halfn )  ) * base ) ;
}
ll findMMI_fermat(ll n,ll M)
{
    return fast_pow(n,M-2);
}
const double PI = 3.14159265358979323846;
//vector<int> v[100001];
bool b[100001];

map<ll,ll> ma;
map<pair<int,int> ,int> pa;
int m,n;
vector<int> x[2];
int dfs(int i)
{

	int k=0;

	stack<pair<int,int> > s;
	s.push(mp(i,k));
	while(!s.empty())
	{
		pair<int,int> t=s.top();
		s.pop();
//		if(ma[t.F]!=0&&ma[t.F]!=t.S)
//		{
//			cout<<t.F<<" "<<t.S;
//			return -1;
//		}
		if(b[t.F]==false)
		{
			b[t.F]=true;
//			cout<<t.F<<" "<<t.S<<'\n';
			ma[t.F]=t.S+1;
			x[t.S].pb(t.F);
			t.S=(t.S+1)%2;

			for(int i=1;i<=n;i++)
			{
				if(pa[mp(t.F,i)]==1)
	           s.push(mp(i,t.S));

			}

		}

	}

}

int main()
{
	memset(b,false,sizeof(b));
     //int m,n;
     cin>>n>>m;
     for(int i=0;i<m;i++)
     {
     	int x,y;
     	cin>>x>>y;
     	pa[mp(x,y)]=1;
     	pa[mp(y,x)]=1;
  //   	v[x].pb(y);
    // 	v[y].pb(x);

	 }
	 for(int i=1;i<=n;i++)
	 {
	 	if(b[i]==false)
	 	{
	 		dfs(i);//==-1)

		}
	 }
	 for(int i=0;i<x[0].size();i++ )
	 for(int j=i+1;j<x[0].size();j++)
	 {
	 	if(pa[mp(x[0][i],x[0][j])]==1)
	 	{
	 		cout<<"-1";
	 		return 0;
		 }

	 }
	 	 for(int i=0;i<x[1].size();i++ )
	 for(int j=i+1;j<x[1].size();j++)
	 {
	 	if(pa[mp(x[1][i],x[1][j])]==1)
	 	{
	 		cout<<"-1";
	 		return 0;
		 }

	 }

	 cout<<x[0].size()<<'\n';

	 for(int i=0;i<x[0].size();i++)
	 cout<<x[0][i]<<" ";

	 cout<<'\n';
	 cout<<x[1].size()<<'\n';

	 for(int i=0;i<x[1].size();i++)
	 cout<<x[1][i]<<" ";
     //map<int,int> ma,pa;
   //  vector<pair<int,int> > v;
     //set<int>c,d;

	return 0;
}


#include<iostream>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<string.h>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include <queue>
#include<string>
#include<sstream>
#include<stack>
#include <iomanip>
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
#define rep(i,A,B) for(int i=A;i<=B;i++)
#define pb push_back
#define mp make_pair
#define S second
#define F first
#define all(c) (c).begin(), (c).end()
#define vectorIterate(v) for(auto it=v.begin(); it!=v.end();it++)
#define mod 1000000007

ll gcd(ll a, ll b)
{
   if (b==0) return a;
   return gcd(b,a%b);
}
ll lcm(ll a, ll b)
{
   return b*a/gcd(a,b);
}

ll abs1(ll a)
{
	if(a<0)
	return -1*a;
	else return a;
}
ll max(ll a,ll b)
{
	if(a>b)
	return a;
	return b;
}
ll fast_pow(long long base, long long n)
{
    if(n==0)
       return 1;
    if(n==1)
    return base;
    long long halfn=fast_pow(base,n/2);
    if(n%2==0)
        return ( halfn * halfn );
    else
        return ( ( ( halfn * halfn )  ) * base ) ;
}
ll findMMI_fermat(ll n,ll M)
{
    return fast_pow(n,M-2);
}
const double PI = 3.14159265358979323846;
vector<int> v[100001];
bool b[1000001];

map<ll,ll> ma;
map<pair<int,int> ,int> pa;

vector<int> x[2];
int dfs(int i)
{

	int k=0;

	stack<pair<int,int> > s;
	s.push(mp(i,k));
	while(!s.empty())
	{
		pair<int,int> t=s.top();
		s.pop();
//		if(ma[t.F]!=0&&ma[t.F]!=t.S)
//		{
//			cout<<t.F<<" "<<t.S;
//			return -1;
//		}
		if(b[t.F]==false)
		{
			b[t.F]=true;
//			cout<<t.F<<" "<<t.S<<'\n';
			ma[t.F]=t.S+1;
			x[t.S].pb(t.F);
			t.S=(t.S+1)%2;

			for(int i=0;i<v[t.F].size();i++)
			{
	           s.push(mp(v[t.F][i],t.S));

			}

		}

	}

}

int main()
{
	memset(b,false,sizeof(b));
     int m,n;
     cin>>n>>m;
     for(int i=0;i<m;i++)
     {
     	int x,y;
     	cin>>x>>y;
     	pa[mp(x,y)]=1;
     	pa[mp(y,x)]=1;
     	v[x].pb(y);
     	v[y].pb(x);

	 }
	 for(int i=1;i<=n;i++)
	 {
	 	if(b[i]==false)
	 	{
	 		dfs(i);//==-1)

		}
	 }
	 for(int i=0;i<x[0].size();i++ )
	 for(int j=i+1;j<x[0].size();j++)
	 {
	 	if(pa[mp(x[0][i],x[0][j])]==1)
	 	{
	 		cout<<"-1";
	 		return 0;
		 }

	 }
	 	 for(int i=0;i<x[1].size();i++ )
	 for(int j=i+1;j<x[1].size();j++)
	 {
	 	if(pa[mp(x[1][i],x[1][j])]==1)
	 	{
	 		cout<<"-1";
	 		return 0;
		 }

	 }

	 cout<<x[0].size()<<'\n';

	 for(int i=0;i<x[0].size();i++)
	 cout<<x[0][i]<<" ";

	 cout<<'\n';
	 cout<<x[1].size()<<'\n';

	 for(int i=0;i<x[1].size();i++)
	 cout<<x[1][i]<<" ";
     //map<int,int> ma,pa;
   //  vector<pair<int,int> > v;
     //set<int>c,d;

	return 0;
}


#include<iostream>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<string.h>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include <queue>
#include<string>
#include<sstream>
#include<stack>
#include <iomanip>
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
#define rep(i,A,B) for(int i=A;i<=B;i++)
#define pb push_back
#define mp make_pair
#define S second
#define F first
#define all(c) (c).begin(), (c).end()
#define vectorIterate(v) for(auto it=v.begin(); it!=v.end();it++)
#define mod 1000000007

ll gcd(ll a, ll b)
{
   if (b==0) return a;
   return gcd(b,a%b);
}
ll lcm(ll a, ll b)
{
   return b*a/gcd(a,b);
}

ll abs1(ll a)
{
	if(a<0)
	return -1*a;
	else return a;
}
ll max(ll a,ll b)
{
	if(a>b)
	return a;
	return b;
}
ll fast_pow(long long base, long long n)
{
    if(n==0)
       return 1;
    if(n==1)
    return base;
    long long halfn=fast_pow(base,n/2);
    if(n%2==0)
        return ( halfn * halfn );
    else
        return ( ( ( halfn * halfn )  ) * base ) ;
}
ll findMMI_fermat(ll n,ll M)
{
    return fast_pow(n,M-2);
}
const double PI = 3.14159265358979323846;
vector<int> v[100001];
bool b[1000001];
int color[100001];
//map<ll,ll> ma;
vector<int> x[2];
void dfs(int i,int l)
{
	  if(b[i]==true)
	  return;
	  if(l==1)
	  l=2;
	  else if(l==2)
	  l=1;
	  color[i]=l;
	  b[i]=true;
	  x[l-1].pb(i);

	  for(int j=0;j<v[i].size();j++)
	  {
	  	 dfs(v[i][j],l);
	  }

}

int main()
{
	memset(b,false,sizeof(b));
     int m,n;
     cin>>n>>m;
     for(int i=0;i<m;i++)
     {
     	int x,y;
     	cin>>x>>y;
     	v[x].pb(y);
     	v[y].pb(x);

	 }
	 for(int i=1;i<=n;i++)
	 {
	 	if(b[i]==false)
	 	{
	 	     dfs(i,1);

		    }
     }

     for(int i=1;i<=n;i++)
     {
     	for(int j=0;j<v[i].size();j++)
     	{

     		if(color[i]==color[v[i][j]])
     		{
     			cout<<-1;
     			return 0;
			 }
		 }

	 }

	 cout<<x[0].size()<<'\n';

	 for(int i=0;i<x[0].size();i++)
	 cout<<x[0][i]<<" ";

	 cout<<'\n';
	 cout<<x[1].size()<<'\n';

	 for(int i=0;i<x[1].size();i++)
	 cout<<x[1][i]<<" ";
     //map<int,int> ma,pa;
   //  vector<pair<int,int> > v;
     //set<int>c,d;

	return 0;
}


#include<iostream>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<string.h>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include <queue>
#include<string>
#include<sstream>
#include<stack>
#include <iomanip>
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
#define rep(i,A,B) for(int i=A;i<=B;i++)
#define pb push_back
#define mp make_pair
#define S second
#define F first
#define all(c) (c).begin(), (c).end()
#define vectorIterate(v) for(auto it=v.begin(); it!=v.end();it++)
#define mod 1000000007

ll gcd(ll a, ll b)
{
   if (b==0) return a;
   return gcd(b,a%b);
}
ll lcm(ll a, ll b)
{
   return b*a/gcd(a,b);
}

ll abs1(ll a)
{
	if(a<0)
	return -1*a;
	else return a;
}
ll max(ll a,ll b)
{
	if(a>b)
	return a;
	return b;
}
ll fast_pow(long long base, long long n)
{
    if(n==0)
       return 1;
    if(n==1)
    return base;
    long long halfn=fast_pow(base,n/2);
    if(n%2==0)
        return ( halfn * halfn );
    else
        return ( ( ( halfn * halfn )  ) * base ) ;
}
ll findMMI_fermat(ll n,ll M)
{
    return fast_pow(n,M-2);
}
const double PI = 3.14159265358979323846;
vector<int> v[100001];
bool b[1000001];

//map<ll,ll> ma;
//map<pair<int,int> ,int> pa;
int m,n;
vector<int> x[2];
int dfs(int i)
{

	int k=0;

	stack<pair<int,int> > s;
	s.push(mp(i,k));
	while(!s.empty())
	{
		pair<int,int> t=s.top();
		s.pop();
//		if(ma[t.F]!=0&&ma[t.F]!=t.S)
//		{
//			cout<<t.F<<" "<<t.S;
//			return -1;
//		}
		if(b[t.F]==false)
		{
			b[t.F]=true;
//			cout<<t.F<<" "<<t.S<<'\n';
//			ma[t.F]=t.S+1;
			x[t.S].pb(t.F);
			t.S=(t.S+1)%2;

			for(int i=1;i<=n;i++)
			{
				if(v[t.F][i]==1)
	           s.push(mp(i,t.S));

			}

		}

	}

}

int main()
{

	memset(b,false,sizeof(b));
     //int m,n;
     //cout<<v[0][0];
     cin>>n>>m;
     for(int i=0;i<=n;i++)
     {
     	v[i].resize(100001);
	 }
     for(int i=0;i<m;i++)
     {
     	int x,y;
     	cin>>x>>y;
     	v[x][y]=1;
     	v[y][x]=1;
  //   	pa[mp(x,y)]=1;
    // 	pa[mp(y,x)]=1;
  //   	v[x].pb(y);
    // 	v[y].pb(x);

	 }
	 for(int i=1;i<=n;i++)
	 {
	 	if(b[i]==false)
	 	{
	 		dfs(i);//==-1)

		}
	 }
	 for(int i=0;i<x[0].size();i++ )
	 for(int j=i+1;j<x[0].size();j++)
	 {
	 	if(v[x[0][i]][x[0][j]]==1)
	 	{
	 		cout<<"-1";
	 		return 0;
		 }

	 }
	 	 for(int i=0;i<x[1].size();i++ )
	 for(int j=i+1;j<x[1].size();j++)
	 {
	 	if(v[x[1][i]][x[1][j]]==1)
	 	{
	 		cout<<"-1";
	 		return 0;
		 }

	 }

	 cout<<x[0].size()<<'\n';

	 for(int i=0;i<x[0].size();i++)
	 cout<<x[0][i]<<" ";

	 cout<<'\n';
	 cout<<x[1].size()<<'\n';

	 for(int i=0;i<x[1].size();i++)
	 cout<<x[1][i]<<" ";
     //map<int,int> ma,pa;
   //  vector<pair<int,int> > v;
     //set<int>c,d;

	return 0;
}


#include<iostream>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<string.h>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include <queue>
#include<string>
#include<sstream>
#include<stack>
#include <iomanip>
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
#define rep(i,A,B) for(int i=A;i<=B;i++)
#define pb push_back
#define mp make_pair
#define S second
#define F first
#define all(c) (c).begin(), (c).end()
#define vectorIterate(v) for(auto it=v.begin(); it!=v.end();it++)
#define mod 1000000007

ll gcd(ll a, ll b)
{
   if (b==0) return a;
   return gcd(b,a%b);
}
ll lcm(ll a, ll b)
{
   return b*a/gcd(a,b);
}

ll abs1(ll a)
{
	if(a<0)
	return -1*a;
	else return a;
}
ll max(ll a,ll b)
{
	if(a>b)
	return a;
	return b;
}
ll fast_pow(long long base, long long n)
{
    if(n==0)
       return 1;
    if(n==1)
    return base;
    long long halfn=fast_pow(base,n/2);
    if(n%2==0)
        return ( halfn * halfn );
    else
        return ( ( ( halfn * halfn )  ) * base ) ;
}
ll findMMI_fermat(ll n,ll M)
{
    return fast_pow(n,M-2);
}
const double PI = 3.14159265358979323846;
//vector<int> v[100001];
bool b[1000001];

map<ll,ll> ma;
map<pair<int,int> ,int> pa;
int m,n;
vector<int> x[2];
int dfs(int i)
{

	int k=0;

	stack<pair<int,int> > s;
	s.push(mp(i,k));
	while(!s.empty())
	{
		pair<int,int> t=s.top();
		s.pop();
//		if(ma[t.F]!=0&&ma[t.F]!=t.S)
//		{
//			cout<<t.F<<" "<<t.S;
//			return -1;
//		}
		if(b[t.F]==false)
		{
			b[t.F]=true;
//			cout<<t.F<<" "<<t.S<<'\n';
			ma[t.F]=t.S+1;
			x[t.S].pb(t.F);
			t.S=(t.S+1)%2;

			for(int i=1;i<=n;i++)
			{
				if(pa[mp(t.F,i)]==1)
	           s.push(mp(i,t.S));

			}

		}

	}

}

int main()
{
	memset(b,false,sizeof(b));
     //int m,n;
     cin>>n>>m;
     for(int i=0;i<m;i++)
     {
     	int x,y;
     	cin>>x>>y;
     	pa[mp(x,y)]=1;
     	pa[mp(y,x)]=1;
  //   	v[x].pb(y);
    // 	v[y].pb(x);

	 }
	 for(int i=1;i<=n;i++)
	 {
	 	if(b[i]==false)
	 	{
	 		dfs(i);//==-1)

		}
	 }
	 for(int i=0;i<x[0].size();i++ )
	 for(int j=i+1;j<x[0].size();j++)
	 {
	 	if(pa[mp(x[0][i],x[0][j])]==1)
	 	{
	 		cout<<"-1";
	 		return 0;
		 }

	 }
	 	 for(int i=0;i<x[1].size();i++ )
	 for(int j=i+1;j<x[1].size();j++)
	 {
	 	if(pa[mp(x[1][i],x[1][j])]==1)
	 	{
	 		cout<<"-1";
	 		return 0;
		 }

	 }

	 cout<<x[0].size()<<'\n';

	 for(int i=0;i<x[0].size();i++)
	 cout<<x[0][i]<<" ";

	 cout<<'\n';
	 cout<<x[1].size()<<'\n';

	 for(int i=0;i<x[1].size();i++)
	 cout<<x[1][i]<<" ";
     //map<int,int> ma,pa;
   //  vector<pair<int,int> > v;
     //set<int>c,d;

	return 0;
}


#include<iostream>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<string.h>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include <queue>
#include<string>
#include<sstream>
#include<stack>
#include <iomanip>
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
#define rep(i,A,B) for(int i=A;i<=B;i++)
#define pb push_back
#define mp make_pair
#define S second
#define F first
#define all(c) (c).begin(), (c).end()
#define vectorIterate(v) for(auto it=v.begin(); it!=v.end();it++)
#define mod 1000000007

ll gcd(ll a, ll b)
{
   if (b==0) return a;
   return gcd(b,a%b);
}
ll lcm(ll a, ll b)
{
   return b*a/gcd(a,b);
}

ll abs1(ll a)
{
	if(a<0)
	return -1*a;
	else return a;
}
ll max(ll a,ll b)
{
	if(a>b)
	return a;
	return b;
}
ll fast_pow(long long base, long long n)
{
    if(n==0)
       return 1;
    if(n==1)
    return base;
    long long halfn=fast_pow(base,n/2);
    if(n%2==0)
        return ( halfn * halfn );
    else
        return ( ( ( halfn * halfn )  ) * base ) ;
}
ll findMMI_fermat(ll n,ll M)
{
    return fast_pow(n,M-2);
}
const double PI = 3.14159265358979323846;
vector<int> v[100001];
bool b[1000001];
map<ll,ll> ma;
vector<int> x[2];
int dfs(int i)
{

	int k=0;

	stack<pair<int,int> > s;
	s.push(mp(i,k));
	while(!s.empty())
	{
		pair<int,int> t=s.top();
		s.pop();
		/*if(ma[t.F]!=0&&ma[t.F]!=t.S)
		{
			cout<<t.F<<" "<<t.S;
			return -1;
		}*/
		if(b[t.F]==false)
		{
			b[t.F]=true;
//			cout<<t.F<<" "<<t.S<<'\n';
			ma[t.F]=t.S+1;
			x[t.S].pb(t.F);
			t.S=(t.S+1)%2;

			for(int i=0;i<v[t.F].size();i++)
			{
	           s.push(mp(v[t.F][i],t.S));

			}

		}

	}

}

int main()
{
	memset(b,false,sizeof(b));
     int m,n;
     cin>>n>>m;
     for(int i=0;i<m;i++)
     {
     	int x,y;
     	cin>>x>>y;
     	v[x].pb(y);
     	v[y].pb(x);

	 }
	 for(int i=1;i<=n;i++)
	 {
	 	if(b[i]==false)
	 	{
	 		if(dfs(i)==-1)
			 {
			cout<<-1 ;
			return 0;
		    }
		}
	 }

	 cout<<x[0].size()<<'\n';

	 for(int i=0;i<x[0].size();i++)
	 cout<<x[0][i]<<" ";

	 cout<<'\n';
	 cout<<x[1].size()<<'\n';

	 for(int i=0;i<x[1].size();i++)
	 cout<<x[1][i]<<" ";
     //map<int,int> ma,pa;
   //  vector<pair<int,int> > v;
     //set<int>c,d;

	return 0;
}


#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

int* color;
int num_zero_col;
int num_one_col;
bool found ;
bool* visited;
// This class represents a directed graph using adjacency list representation
class Graph
{
    int V;    // No. of vertices
    list<int> *adj;    // Pointer to an array containing adjacency lists
public:
    Graph(int V);  // Constructor
    void addEdge(int v, int w); // function to add an edge to graph
    void BFS(int s);  // prints BFS traversal from a given source s
};

Graph::Graph(int V)
{
    this->V = V;
    adj = new list<int>[V];
}

void Graph::addEdge(int v, int w)
{
    adj[v].push_back(w); // Add w to v’s list.
    adj[w].push_back(v);
}

void Graph::BFS(int s)
{
    // Mark all the vertices as not visited

    // Create a queue for BFS
    list<int> queue;

    // Mark the current node as visited and enqueue it
    visited[s] = true;
    queue.push_back(s);
    color[s] = 0;
    // 'i' will be used to get all adjacent vertices of a vertex
    list<int>::iterator i;

    while(!queue.empty())
    {
        // Dequeue a vertex from queue and print it
        s = queue.front();
        //cout << (s+1) <<endl;
        queue.pop_front();
        if(color[s] == 0){
          num_zero_col++;
        }
        else{
          if(color[s] == 1){
            num_one_col++;
          }
        }
        int col = 1 - color[s];

        // Get all adjacent vertices of the dequeued vertex s
        // If a adjacent has not been visited, then mark it visited
        // and enqueue it
        //cout<<"adjacent : "<<endl;
        for(i = adj[s].begin(); i != adj[s].end(); ++i)
        {
            if(!visited[*i])
            {
              //cout<<(*i) + 1 <<" ";
                visited[*i] = true;

                color[*i] = col;

                queue.push_back(*i);

            }
            else{
              if(color[*i] != col){
                found = true;
              }
            }
        }
        //cout<<endl;
    }
}

// Driver program to test methods of graph class
int main()
{
    // Create a graph given in the above diagram
  int n;
  int m;
  cin>>n>>m;

    Graph g(n);
    color = new int[n];
    for(int i=0;i<n;i++){
      color[i] = -1;
    }
    num_zero_col = 0;
    num_one_col = 0;
    found = false;
    int a;
    int b;
    for(int i=0;i<m;i++){
      cin>>a>>b;
      a--;
      b--;
    g.addEdge(a, b);

 }
    visited = new bool[n];
    for(int i = 0; i < n; i++)
        {visited[i] = false;}
for(int i=0;i<n;i++){
  if(color[i] == -1){
        //cout << "Following is Breadth First Traversal (starting from vertex "<<(i+1)<<endl;

    g.BFS(i);
    //cout<<endl;
  }
}
    if(found){
      cout<<"-1"<<endl;
    }
    else{
 int count = 0;
 for(int i=0;i<n;i++){
if(color[i] == 0){
count++;}
}
cout<<count<<endl;
for(int i=0;i<n;i++){
if(color[i] == 0){
  cout<<(i+1)<<" " ;
}
}
cout<<endl;
count = 0;
 for(int i=0;i<n;i++){
if(color[i] == 1){
count++;}
}
cout<<count<<endl;
 for(int i=0;i<n;i++){
if(color[i] == 1){
  cout<<(i+1)<<" ";
}
}
cout<<endl;}
 return 0;

}


#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

int* color;
int num_zero_col;
int num_one_col;
bool found ;

// This class represents a directed graph using adjacency list representation
class Graph
{
    int V;    // No. of vertices
    list<int> *adj;    // Pointer to an array containing adjacency lists
public:
    Graph(int V);  // Constructor
    void addEdge(int v, int w); // function to add an edge to graph
    void BFS(int s);  // prints BFS traversal from a given source s
};

Graph::Graph(int V)
{
    this->V = V;
    adj = new list<int>[V];
}

void Graph::addEdge(int v, int w)
{
    adj[v].push_back(w); // Add w to v’s list.
    adj[w].push_back(v);
}

void Graph::BFS(int s)
{
    // Mark all the vertices as not visited
    bool *visited = new bool[V];
    for(int i = 0; i < V; i++)
        visited[i] = false;

    // Create a queue for BFS
    list<int> queue;

    // Mark the current node as visited and enqueue it
    visited[s] = true;
    queue.push_back(s);
    color[s] = 0;
    // 'i' will be used to get all adjacent vertices of a vertex
    list<int>::iterator i;

    while(!queue.empty())
    {
        // Dequeue a vertex from queue and print it
        s = queue.front();
        //cout << (s+1) <<endl;
        queue.pop_front();
        if(color[s] == 0){
          num_zero_col++;
        }
        else{
          if(color[s] == 1){
            num_one_col++;
          }
        }
        int col = 1 - color[s];

        // Get all adjacent vertices of the dequeued vertex s
        // If a adjacent has not been visited, then mark it visited
        // and enqueue it
        //cout<<"adjacent : "<<endl;
        for(i = adj[s].begin(); i != adj[s].end(); ++i)
        {
            if(!visited[*i])
            {
              //cout<<(*i) + 1 <<" ";
                visited[*i] = true;

                color[*i] = col;

                queue.push_back(*i);

            }
            else{
              if(color[*i] != col){
                found = true;
              }
            }
        }
        //cout<<endl;
    }
}

// Driver program to test methods of graph class
int main()
{
    // Create a graph given in the above diagram
  int n;
  int m;
  cin>>n>>m;

    Graph g(n);
    color = new int[n];
    for(int i=0;i<n;i++){
      color[i] = -1;
    }
    num_zero_col = 0;
    num_one_col = 0;
    found = false;
    int a;
    int b;
    for(int i=0;i<m;i++){
      cin>>a>>b;
      a--;
      b--;
    g.addEdge(a, b);

 }
for(int i=0;i<n;i++){
  if(color[i] == -1){
        //cout << "Following is Breadth First Traversal (starting from vertex "<<(i+1)<<endl;

    g.BFS(i);
    //cout<<endl;
  }
}
    if(found){
      cout<<"-1"<<endl;
    }
    else{
 int count = 0;
 for(int i=0;i<n;i++){
if(color[i] == 0){
count++;}
}
cout<<count<<endl;
for(int i=0;i<n;i++){
if(color[i] == 0){
  cout<<(i+1)<<" " ;
}
}
cout<<endl;
count = 0;
 for(int i=0;i<n;i++){
if(color[i] == 1){
count++;}
}
cout<<count<<endl;
 for(int i=0;i<n;i++){
if(color[i] == 1){
  cout<<(i+1)<<" ";
}
}
cout<<endl;}
 return 0;

}


#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

int64_t* color;
int64_t num_zero_col;
int64_t num_one_col;
bool found ;

// This class represents a directed graph using adjacency list representation
class Graph
{
    int64_t V;    // No. of vertices
    list<int64_t> *adj;    // Point64_ter to an array containing adjacency lists
public:
    Graph(int64_t V);  // Constructor
    void addEdge(int64_t v, int64_t w); // function to add an edge to graph
    void BFS(int64_t s);  // print64_ts BFS traversal from a given source s
};

Graph::Graph(int64_t V)
{
    this->V = V;
    adj = new list<int64_t>[V];
}

void Graph::addEdge(int64_t v, int64_t w)
{
    adj[v].push_back(w); // Add w to v’s list.
    adj[w].push_back(v);
}

void Graph::BFS(int64_t s)
{
    // Mark all the vertices as not visited
    bool *visited = new bool[V];
    for(int64_t i = 0; i < V; i++)
        visited[i] = false;

    // Create a queue for BFS
    list<int64_t> queue;

    // Mark the current node as visited and enqueue it
    visited[s] = true;
    queue.push_back(s);
    color[s] = 0;
    // 'i' will be used to get all adjacent vertices of a vertex
    list<int64_t>::iterator i;

    while(!queue.empty())
    {
        // Dequeue a vertex from queue and print64_t it
        s = queue.front();
        //cout << (s+1) <<endl;
        queue.pop_front();
        if(color[s] == 0){
          num_zero_col++;
        }
        else{
          if(color[s] == 1){
            num_one_col++;
          }
        }
        int64_t col = 1 - color[s];

        // Get all adjacent vertices of the dequeued vertex s
        // If a adjacent has not been visited, then mark it visited
        // and enqueue it
        //cout<<"adjacent : "<<endl;
        for(i = adj[s].begin(); i != adj[s].end(); ++i)
        {
            if(!visited[*i])
            {
              //cout<<(*i) + 1 <<" ";
                visited[*i] = true;

                color[*i] = col;

                queue.push_back(*i);

            }
            else{
              if(color[*i] != col){
                found = true;
              }
            }
        }
        //cout<<endl;
    }
}

// Driver program to test methods of graph class
int main()
{
    // Create a graph given in the above diagram
  int64_t n;
  int64_t m;
  cin>>n>>m;

    Graph g(n);
    color = new int64_t[n];
    for(int64_t i=0;i<n;i++){
      color[i] = -1;
    }
    num_zero_col = 0;
    num_one_col = 0;
    found = false;
    int64_t a;
    int64_t b;
    for(int64_t i=0;i<m;i++){
      cin>>a>>b;
      a--;
      b--;
    g.addEdge(a, b);

 }
for(int64_t i=0;i<n;i++){
  if(color[i] == -1){
        //cout << "Following is Breadth First Traversal (starting from vertex "<<(i+1)<<endl;

    g.BFS(i);
    //cout<<endl;
  }
}
    if(found){
      cout<<"-1"<<endl;
    }
    else{
 int64_t count = 0;
 for(int64_t i=0;i<n;i++){
if(color[i] == 0){
count++;}
}
cout<<count<<endl;
for(int64_t i=0;i<n;i++){
if(color[i] == 0){
  cout<<(i+1)<<" " ;
}
}
cout<<endl;
count = 0;
 for(int64_t i=0;i<n;i++){
if(color[i] == 1){
count++;}
}
cout<<count<<endl;
 for(int64_t i=0;i<n;i++){
if(color[i] == 1){
  cout<<(i+1)<<" ";
}
}
cout<<endl;}
 return 0;

}


#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

int64_t* color;
int64_t num_zero_col;
int64_t num_one_col;
bool found ;

// This class represents a directed graph using adjacency list representation
class Graph
{
    int64_t V;    // No. of vertices
    list<int64_t> *adj;    // Point64_ter to an array containing adjacency lists
public:
    Graph(int64_t V);  // Constructor
    void addEdge(int64_t v, int64_t w); // function to add an edge to graph
    void BFS(int64_t s);  // print64_ts BFS traversal from a given source s
};

Graph::Graph(int64_t V)
{
    this->V = V;
    adj = new list<int64_t>[V];
}

void Graph::addEdge(int64_t v, int64_t w)
{
    adj[v].push_back(w); // Add w to v’s list.
}

void Graph::BFS(int64_t s)
{
    // Mark all the vertices as not visited
    bool *visited = new bool[V];
    for(int64_t i = 0; i < V; i++)
        visited[i] = false;

    // Create a queue for BFS
    list<int64_t> queue;

    // Mark the current node as visited and enqueue it
    visited[s] = true;
    queue.push_back(s);
    color[s] = 0;
    // 'i' will be used to get all adjacent vertices of a vertex
    list<int64_t>::iterator i;

    while(!queue.empty())
    {
        // Dequeue a vertex from queue and print64_t it
        s = queue.front();
       // cout << s << " ";
        queue.pop_front();
        if(color[s] == 0){
          num_zero_col++;
        }
        else{
          if(color[s] == 1){
            num_one_col++;
          }
        }
        int64_t col = 1 - color[s];

        // Get all adjacent vertices of the dequeued vertex s
        // If a adjacent has not been visited, then mark it visited
        // and enqueue it
        for(i = adj[s].begin(); i != adj[s].end(); ++i)
        {
            if(!visited[*i])
            {
                visited[*i] = true;

                color[*i] = col;

                queue.push_back(*i);

            }
            else{
              if(color[*i] != col){
                found = true;
              }
            }
        }
    }
}

// Driver program to test methods of graph class
int main()
{
    // Create a graph given in the above diagram
  int64_t n;
  int64_t m;
  cin>>n>>m;

    Graph g(n);
    color = new int64_t[n];
    for(int64_t i=0;i<n;i++){
      color[i] = -1;
    }
    num_zero_col = 0;
    num_one_col = 0;
    found = false;
    int64_t a;
    int64_t b;
    for(int64_t i=0;i<m;i++){
      cin>>a>>b;
      a--;
      b--;
    g.addEdge(a, b);

 }
   // cout << "Following is Breadth First Traversal (starting from vertex 2) \n";
for(int64_t i=0;i<n;i++){
  if(color[i] == -1){
    g.BFS(i);
  }
}
    if(found){
      cout<<"-1"<<endl;
    }
    else{
 int64_t count = 0;
 for(int64_t i=0;i<n;i++){
if(color[i] == 0){
count++;}
}
cout<<count<<endl;
for(int64_t i=0;i<n;i++){
if(color[i] == 0){
  cout<<(i+1)<<" " ;
}
}
cout<<endl;
count = 0;
 for(int64_t i=0;i<n;i++){
if(color[i] == 1){
count++;}
}
cout<<count<<endl;
 for(int64_t i=0;i<n;i++){
if(color[i] == 1){
  cout<<(i+1)<<" ";
}
}
cout<<endl;}
 return 0;

}


#include <bits/stdc++.h>
using namespace std ;
int n , m ;
int x , y ;
vector<int>a[2] ;
vector<int>bro[100005] ;
int c[100005] ;
int bfs()
{
        queue <int>q ;
        q.push(1);
        c[1] = 1 ;
        while(!q.empty())
        {
                int u = q.front();
                q.pop() ;
                for( int i = 0 ; i < bro[u].size() ; i++ )
                {
                        int v = bro[u][i] ;
                        //cout << "v = " << v << endl ;
                        if(c[v]==-1)
                        {
                                c[v] = (c[u]^1) ;
                                q.push(v) ;
                        }
                        else if( c[v] != (c[u]^1) ){return -1 ; }
                }
        }
        return 1 ;
}

int main()
{
memset(c,-1,sizeof(c));
cin>>n>>m;
for(int i = 0 ; i < m ; i++ )
{
scanf("%d %d",&x,&y);
bro[x].push_back(y);
bro[y].push_back(x);
}
//cout << "sigh"<<endl ;
int ret = bfs() ;
//cout << "ret " << endl ;
if(ret==-1)cout<<-1 ;
else
{
        for( int i = 1 ;  i <= n ; i++ )if(c[i]!=-1)a[c[i]].push_back(i);// , cout << i << endl ;
        int sz = a[0].size() ;
        cout << sz << endl ;
        for(int i = 0 ; i < sz ; i++ )printf("%d ", a[0][i] ) ;
        cout << endl;
         sz = a[1].size() ;
        cout << sz << endl ;
        for(int i = 0 ; i < sz ; i++ )printf("%d ", a[1][i] ) ;
        cout << endl;
}

return 0 ;
}


#include <bits/stdc++.h>
using namespace std ;
int n , m ;
int x , y ;
vector<int>a[2] ;
vector<int>bro[100005] ;
int c[100005] ;
int bfs(int u )
{
        queue <int>q ;
        q.push(u);
        c[u] = 1 ;
        while(!q.empty())
        {
                int u = q.front();
                q.pop() ;
                for( int i = 0 ; i < bro[u].size() ; i++ )
                {
                        int v = bro[u][i] ;
                        //cout << "v = " << v << endl ;
                        if(c[v]==-1)
                        {
                                c[v] = (c[u]^1) ;
                                q.push(v) ;
                        }
                        else if( c[v] != (c[u]^1) ){return -1 ; }
                }
        }
        return 1 ;
}

int main()
{
memset(c,-1,sizeof(c));
cin>>n>>m;
for(int i = 0 ; i < m ; i++ )
{
scanf("%d %d",&x,&y);
bro[x].push_back(y);
bro[y].push_back(x);
}
//cout << "sigh"<<endl ;
int ret = 0 ;
for( int i = 1 ; i <= n ; i++ )
{
        if(ck[u]==-1)
        {
                ret = bfs(u) ;
                if(ret==-1){break;}
        }
}
//cout << "ret " << endl ;
if(ret==-1)cout<<-1 ;
else
{
        for( int i = 1 ;  i <= n ; i++ )if(c[i]!=-1)a[c[i]].push_back(i);// , cout << i << endl ;
        int sz = a[0].size() ;
        cout << sz << endl ;
        for(int i = 0 ; i < sz ; i++ )printf("%d ", a[0][i] ) ;
        cout << endl;
         sz = a[1].size() ;
        cout << sz << endl ;
        for(int i = 0 ; i < sz ; i++ )printf("%d ", a[1][i] ) ;
        cout << endl;
}

return 0 ;
}


#include <bits/stdc++.h>
using namespace std ;
int n , m ;
int x , y ;
vector<int>a[2] ;
vector<int>bro[100005] ;
int c[100005] ;
int bfs(int u )
{
        queue <int>q ;
        q.push(u);
        c[u] = 1 ;
        while(!q.empty())
        {
                int u = q.front();
                q.pop() ;
                for( int i = 0 ; i < bro[u].size() ; i++ )
                {
                        int v = bro[u][i] ;
                        //cout << "v = " << v << endl ;
                        if(c[v]==-1)
                        {
                                c[v] = (c[u]^1) ;
                                q.push(v) ;
                        }
                        else if( c[v] != (c[u]^1) ){return -1 ; }
                }
        }
        return 1 ;
}

int main()
{
memset(c,-1,sizeof(c));
cin>>n>>m;
for(int i = 0 ; i < m ; i++ )
{
scanf("%d %d",&x,&y);
bro[x].push_back(y);
bro[y].push_back(x);
}
//cout << "sigh"<<endl ;
int ret = 0 ;
for( int i = 1 ; i <= n ; i++ )
{
        if(c[i]==-1)
        {
                ret = bfs(i) ;
                if(ret==-1){break;}
        }
}
//cout << "ret " << endl ;
if(ret==-1)cout<<-1 ;
else
{
        for( int i = 1 ;  i <= n ; i++ )if(c[i]!=-1)a[c[i]].push_back(i);// , cout << i << endl ;
        int sz = a[0].size() ;
        cout << sz << endl ;
        for(int i = 0 ; i < sz ; i++ )printf("%d ", a[0][i] ) ;
        cout << endl;
         sz = a[1].size() ;
        cout << sz << endl ;
        for(int i = 0 ; i < sz ; i++ )printf("%d ", a[1][i] ) ;
        cout << endl;
}

return 0 ;
}


#include <bits/stdc++.h>
using namespace std ;
int n , m ;
int x , y ;
vector<int>a[2] ;
vector<int>bro[100005] ;
int c[100005] ;
int bfs(int u )
{
        queue <int>q ;
        q.push(u);
        c[u] = 1 ;
        while(!q.empty())
        {
                int u = q.front();
                q.pop() ;
                for( int i = 0 ; i < bro[u].size() ; i++ )
                {
                        int v = bro[u][i] ;
                        //cout << "v = " << v << endl ;
                        if(c[v]==-1)
                        {
                                c[v] = (c[u]^1) ;
                                q.push(v) ;
                        }
                        else if( c[v] != (c[u]^1) ){return -1 ; }
                }
        }
        return 1 ;
}

int main()
{
memset(c,-1,sizeof(c));
cin>>n>>m;
for(int i = 0 ; i < m ; i++ )
{
scanf("%d %d",&x,&y);
bro[x].push_back(y);
bro[y].push_back(x);
}
//cout << "sigh"<<endl ;
int ret = 0 ;
for( int i = 1 ; i <= n ; i++ )
{
        if(c[u]==-1)
        {
                ret = bfs(u) ;
                if(ret==-1){break;}
        }
}
//cout << "ret " << endl ;
if(ret==-1)cout<<-1 ;
else
{
        for( int i = 1 ;  i <= n ; i++ )if(c[i]!=-1)a[c[i]].push_back(i);// , cout << i << endl ;
        int sz = a[0].size() ;
        cout << sz << endl ;
        for(int i = 0 ; i < sz ; i++ )printf("%d ", a[0][i] ) ;
        cout << endl;
         sz = a[1].size() ;
        cout << sz << endl ;
        for(int i = 0 ; i < sz ; i++ )printf("%d ", a[1][i] ) ;
        cout << endl;
}

return 0 ;
}


#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
#define N 111111
vector<int> e[N];
int n, m;

int p[N];

bool dfs(int k, int col) {
	if (p[k] != -1 && p[k] != col) {
		return 0;
	}
	p[k] = col;
	for (int i = 0; i < e[k].size(); ++i) {
		int u = e[k][i];
		if (dfs(u, col ^ 1) == 0) return 0;
	}
	return 1;
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; ++i) {
		int x, y;
		scanf("%d%d", &x, &y); --x; --y;
		e[x].push_back(y);
		e[y].push_back(x);
	}
	memset(p, -1, sizeof(p));
	int flag = 1;
	for (int i = 0; i < n; ++i) {
		if (p[i] == -1) {
			flag = dfs(i, 0);
		}
	}
	if (flag) {
		int count = 0;
		for (int i = 0; i < n; ++i) {
			if (p[i]) count++;
		}
		printf("%d\n", count);
		for (int i = 0; i < n; ++i) {
			if (p[i]) printf("%d ", i + 1);
		}
		printf("%d\n", n - count);
		for (int i = 0; i < n; ++i) {
			if (p[i] == 0) printf("%d ", i + 1);
		}
	}
	else {
		puts("-1");
	}

	return 0;
}


#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
#define N 111111
vector<int> e[N];
int n, m;

int p[N];

bool dfs(int k, int col) {
	if (p[k] != -1) {
		return p[k] == col;
	}
	p[k] = col;
	for (int i = 0; i < e[k].size(); ++i) {
		int u = e[k][i];
		if (dfs(u, col ^ 1) == 0) return 0;
	}
	return 1;
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; ++i) {
		int x, y;
		scanf("%d%d", &x, &y); --x; --y;
		e[x].push_back(y);
		e[y].push_back(x);
	}
	memset(p, -1, sizeof(p));
	int flag = 1;
	for (int i = 0; i < n; ++i) {
		if (p[i] == -1) {
			flag = dfs(i, 0);
		}
	}
	if (flag) {
		int count = 0;
		for (int i = 0; i < n; ++i) {
			if (p[i]) count++;
		}
		printf("%d\n", count);
		for (int i = 0; i < n; ++i) {
			if (p[i]) printf("%d ", i + 1);
		}
		printf("%d\n", n - count);
		for (int i = 0; i < n; ++i) {
			if (p[i] == 0) printf("%d ", i + 1);
		}
	}
	else {
		puts("-1");
	}

	return 0;
}


#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
#define N 111111
vector<int> e[N];
int n, m;

int p[N];

bool dfs(int k, int col) {
	if (p[k] != -1) {
		return p[k] == col;
	}
	p[k] = col;
	for (int i = 0; i < e[k].size(); ++i) {
		int u = e[k][i];
		if (dfs(u, col ^ 1) == 0) return 0;
	}
	return 1;
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; ++i) {
		int x, y;
		scanf("%d%d", &x, &y); --x; --y;
		e[x].push_back(y);
		e[y].push_back(x);
	}
	memset(p, -1, sizeof(p));
	int flag = 1;
	for (int i = 0; i < n; ++i) {
		if (p[i] == -1) {
			flag &= dfs(i, 0);
		}
	}
	if (flag) {
		int count = 0;
		for (int i = 0; i < n; ++i) {
			if (p[i]) count++;
		}
		printf("%d\n", count);
		for (int i = 0; i < n; ++i) {
			if (p[i]) printf("%d ", i + 1);
		}
		printf("\n%d\n", n - count);
		for (int i = 0; i < n; ++i) {
			if (p[i] == 0) printf("%d ", i + 1);
		}
	}
	else {
		puts("-1");
	}

	return 0;
}


#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<bitset>
#include<numeric>
#include<vector>
#include<string>
#include<iterator>
#include<cstring>
#include<functional>
#define INF 0x3f3f3f3f
#define ms(a,b) memset(a,b,sizeof(a))
#define pi 3.14159265358979
#define MOD 1000000007
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;

typedef pair<int, int> P;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 100000 + 10;
vector<int> g[maxn], v[2];
bool ok;
int color[maxn];  ///二分图染色法

void dfs(int k, int c) ///顶点k，染色c
{
	if (color[k] != -1) ///顶点k已染色
	{
		if (color[k] != c) ///染得色不同，即同子集间的两个顶点有边
			ok = true;
		return;
	}
	color[k] = c; ///顶点k染色
	v[c].push_back(k);
	int len = g[k].size(); ///边数
	for (int i = 0; i < len; ++i)
		dfs(g[k][i], c ^ 1); /// 0 -> 1,, 1 -> 0;相邻顶点然不同的颜色，位异或，0^1=1，1^1=0
}
void print(vector <int> & t)
{
	int len = t.size();
	printf("%d\n", len);
	for (int i = 0; i < len; ++i)
		i ? printf(" ") : printf("%d", t[i]);
	printf("\n");
}
int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; ++i)
	{
		int u, w;
		scanf("%d%d", &u, &w);
		g[u].push_back(w);
		g[w].push_back(u);
	}
	ok = false;
	memset(color, -1, sizeof color);
	for (int i = 1; i <= n; ++i)
	{
		if (color[i] == -1) ///未染色
			dfs(i, 0); ///染0色
	}
	if (ok) ///不是二分图
		printf("-1\n");
	else
	{
		print(v[1]);
		print(v[0]); ///输出左右子集
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<bitset>
#include<numeric>
#include<vector>
#include<string>
#include<iterator>
#include<cstring>
#include<functional>
#define INF 0x3f3f3f3f
#define ms(a,b) memset(a,b,sizeof(a))
#define pi 3.14159265358979
#define MOD 1000000007
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;

typedef pair<int, int> P;
typedef long long ll;
typedef unsigned long long ull;
const int MAX = 100010;
struct p
{
	int next, node;
}E[MAX];
int head[MAX], poi[MAX], vis[MAX];
int flag, fre;
void insertt(int x, int y)
{
	p EE = { head[x],y };
	E[fre] = EE;
	head[x] = fre++;
}
void dfs(int root, int color)
{
	for (int i = head[root]; i != -1 && flag; i = E[i].next)
	{
		if (poi[E[i].node] == 0)
		{
			poi[E[i].node] = color*-1;
			dfs(E[i].node, color*-1);
		}
		else
		{
			if (poi[E[i].node] == color)
			{
				flag = 0;
				return;
			}
		}
	}
}
int main()
{
	int n, m;
	flag = 1;
	fre = 0;
	memset(head, -1, sizeof(head));
	memset(poi, 0, sizeof(poi));
	scanf("%d%d", &n, &m);
	int a, b;
	for (int i = 1; i <= m; i++)
	{
		scanf("%d%d", &a, &b);
		insertt(a, b);
		insertt(b, a);
	}
	for (int i = 1; i <= n; i++)
		if (!poi[i] && flag) dfs(i, 1);
	int nset1 = 0;
	int nset2 = 0;
	if (!flag) printf("-1");
	else
	{
		for (int i = 1; i <= n; i++)
		{
			if (poi[i] == 1) nset1++;
			if (poi[i] == -1) nset2++;
		}
		printf("%d\n", nset1);
		for (int i = 1; i <= n; i++)
			if (poi[i] == 1) printf("%d ", i);
		printf("\n%d\n", nset2);
		for (int i = 1; i <= n; i++)
			if (poi[i] == -1) printf("%d ", i);
	}

}


#include<cstdio>
#include<cstring>
#include<cctype>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<list>
typedef long long ll;
typedef unsigned long long llu;
const int MAXN = 100 + 10;
const int MAXT = 100000 + 10;
const int INF = 0x7f7f7f7f;
const double pi = acos(-1.0);
const double EPS = 1e-6;
using namespace std;

int n, m, vis[MAXT];
vector<int> e[MAXT];

bool dfs(int lur, int t){
    int len = e[lur].size();
    if(!len)  return true;
    vis[lur] = t;
    for(int i = 0; i < len; ++i){
        int &tmp = e[lur][i];
        if(vis[tmp] == -t)  continue;
        else if(vis[tmp] == t)  return false;
        if(!dfs(tmp, -t))  return false;
    }
    return true;
}

int main(){
    memset(vis, 0, sizeof vis);
    scanf("%d%d", &n, &m);
    int a, b;
    for(int i = 0; i < m; ++i){
        scanf("%d%d", &a, &b);
        e[a].push_back(b);  e[b].push_back(a);
    }
    bool flag = true;
    for(int i = 1; i <= n; ++i){
        if(vis[i])  continue;
        if(!e[i].size()){
            vis[i] = 2;
            continue;
        }
        if(!dfs(i, 1)){
            flag = false;
            break;
        }
    }
    if(!flag)  printf("-1\n");
    else{
        e[0].clear();  e[1].clear();
        for(int i = 1; i <= n; ++i)
            if(vis[i] == 1)  e[0].push_back(i);
            else if(vis[i] == -1)  e[1].push_back(i);
        a = e[0].size();
        printf("%d\n", a);
        for(int i = 0; i < a; ++i){
            if(i)  printf(" ");
            printf("%d", e[0][i]);
        }
        a = e[1].size();
        printf("\n%d\n", a);
        for(int i = 0; i < a; ++i){
            if(i)  printf(" ");
            printf("%d", e[1][i]);
        }
        printf("\n");
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<bitset>
#include<numeric>
#include<vector>
#include<string>
#include<iterator>
#include<cstring>
#include<functional>
#define INF 0x3f3f3f3f
#define ms(a,b) memset(a,b,sizeof(a))
#define pi 3.14159265358979
#define MOD 1000000007
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;

typedef pair<int, int> P;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 100010;
int col[maxn];
vector<int>v[maxn];
bool dfs(int u, int color)
{
	col[u] = color;
	for (int i = 0; i<v[u].size(); i++)
	{
		int t = v[u][i];
		if (col[t] == color)
		{
			return false;
		}
		else if (col[t] == 0)
		{
			if (!dfs(t, -color))
				return false;
		}
	}
	return true;
}
int main()
{
	memset(col, 0, sizeof(col));
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; i++)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		v[x].push_back(y);
		v[y].push_back(x);
	}
	int flag = true;
	for (int i = 1; i <= n; i++)
	{
		if (col[i] == 0)
		{
			if (!dfs(i, 1))
			{
				flag = false;
				break;
			}
		}
	}
	if (!flag)
		cout << "-1" << endl;
	else
	{
		int cot = 0;
		for (int i = 1; i <= n; i++)
		{
			if (col[i] == 1)
				cot++;
		}
		printf("%d\n", cot);
		for (int i = 1; i <= n; i++)
		{
			if (col[i] == 1)
				printf("%d ", i);
		}
		printf("\n");
		printf("%d\n", n - cot);
		for (int i = 1; i <= n; i++)
		{
			if (col[i] == -1)
			{
				printf("%d ", i);
			}
		}
		cout << endl;
	}
	return 0;
}


#include<iostream>
#include <algorithm>
#include <queue>
using namespace std;
int n,m,a,b,ncc,ret=0,used[100001];
queue<int> q[100001];
void dfs(int i,int sign)
{
    while(!q[i].empty())
        {
            int temp=q[i].front();
            if(used[temp]==0)
            {
                sign==1 ? b++ : a++;
                used[temp]=sign*-1;
                dfs(temp,sign*-1);
            }
            if(used[temp]==used[i]) ret=-1;
            q[i].pop();
        }
}
int main()
{
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        q[a].push(b);q[b].push(a);
    }
    used[1]=1; a++; dfs(1,1);
    for(int i=2;i<=n;i++) if(used[i]==0) dfs(i,1);
    if(ret==-1) cout<<-1;
    else
    {
        cout<< a<<endl;
        for(int i=1;i<=n;i++)
            if(used[i]==1) cout<<i<<" ";
        cout<<endl<<b<<endl;
        for(int i=1;i<=n;i++)
            if(used[i]==-1) cout<<i<<" ";
    }
}


#include<bits/stdc++.h>
using namespace std;
const int MAX=1e5+9;
vector<int> vv[MAX],a;
int n,m,col[MAX];
void dfs(int v)
{
	for (int u=0;u<vv[v].size();u++)
		if (!col[vv[v][u]])
			col[vv[v][u]]=3-col[v],dfs(vv[v][u]);
		else
			if (col[vv[v][u]]==col[v])
				cout<<"-1",exit(0);
}
int main()
{
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n>>m;
	for (int i=0,v,u;i<m;i++) cin>>v>>u,v--,u--,vv[v].push_back(u),vv[u].push_back(v);
	for (int i=0;i<n;i++) if (!col[i]) col[i]=1,dfs(i);
	for (int i=0;i<n;i++) if (col[i]==1) a.push_back(i);
	cout<<a.size()<<endl;
	for (int i=0;i<a.size();i++) cout<<a[i]+1<<" ";
	cout<<endl<<n-a.size()<<endl;
	for (int i=0;i<n;i++) if (col[i]==2) cout<<i+1<<" ";
	return 0;
}


#include<iostream>
#include <algorithm>
#include <queue>
using namespace std;
int n,m,a,b,ncc,ret=0,used[100001];
queue<int> q[100001];
void dfs(int i)
{
    while(!q[i].empty())
        {
            int temp=q[i].front();
            if(used[temp]==0)
            {
                used[i]==1 ? b++ : a++;
                used[temp]=used[i]*-1;
                dfs(temp);
            }
            if(used[temp]==used[i]) cout<<-1,exit(0);
            q[i].pop();
        }
}
int main()
{
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        q[a].push(b);q[b].push(a);
    }
    used[1]=1; a++; dfs(1);
    for(int i=2;i<=n;i++) if(used[i]==0) dfs(i);

        cout<< a<<endl;
        for(int i=1;i<=n;i++)
            if(used[i]==1) cout<<i<<" ";
        cout<<endl<<b<<endl;
        for(int i=1;i<=n;i++)
            if(used[i]==-1) cout<<i<<" ";

}


#include<bits/stdc++.h>

#define NN 111111

using namespace std;

vector<int> adj[NN];

int flag[NN], nn[2], ans[2][NN], ok, vst[NN];

void dfs(int u, int st){

	int beg=nn[1-st];

	for(int i=0; i<adj[u].size(); i++){

		if(flag[adj[u][i]]==st) {ok=1; return ;}

		if(flag[adj[u][i]]!=-1) continue;

		vst[adj[u][i]]=1;

		ans[1-st][nn[1-st]++]=adj[u][i];

		flag[adj[u][i]]=1-st;

	}

	int ed=nn[1-st];

	for(int i=beg; i<ed; i++){

		dfs(ans[1-st][i], 1-st);

	}

}

int main(){

	memset(flag, -1, sizeof(flag));

	int n,m,i,j,u,v;

	cin>>n>>m;

	for(i=0; i<m; i++){

		cin>>u>>v;

		adj[u].push_back(v);

		adj[v].push_back(u);

	}

	flag[1]=0;

	vst[1]=1;

	ans[0][nn[0]++]=1;

	dfs(1, 0);

	for(i=1; i<=n; i++) {

		if(vst[i]) continue;

		if(adj[i].size()==0) continue;

		vst[i]=1;

		flag[i]=0;

		ans[0][nn[0]++]=i;

		dfs(i, 0);

	}

	if(ok) {puts("-1"); return 0;}

	for(i=0; i<2; i++){

		cout<<nn[i]<<endl;

		for(j=0; j<nn[i]; j++){

			cout<<ans[i][j]<<' ';

		}

		cout<<endl;

	}

	return 0;

}


#include<bits/stdc++.h>

#define NN 111111

using namespace std;

vector<int> adj[NN];

int flag[NN], nn[2], ans[2][NN], ok, vst[NN];

void dfs(int u, int st){

	int beg=nn[1-st];

	for(int i=0; i<adj[u].size(); i++){

		if(flag[adj[u][i]]==st) {ok=1; return ;}

		if(flag[adj[u][i]]!=-1) continue;

		vst[adj[u][i]]=1;

		ans[1-st][nn[1-st]++]=adj[u][i];

		flag[adj[u][i]]=1-st;

	}

	int ed=nn[1-st];

	for(int i=beg; i<ed; i++){

		dfs(ans[1-st][i], 1-st);

	}

}

int main(){

	memset(flag, -1, sizeof(flag));

	int n,m,i,j,u,v;

	cin>>n>>m;

	for(i=0; i<m; i++){

		cin>>u>>v;

		adj[u].push_back(v);

		adj[v].push_back(u);

	}

	flag[1]=0;

	vst[1]=1;

	ans[0][nn[0]++]=1;

	dfs(1, 0);

	for(i=1; i<=n; i++) {

		if(vst[i]) continue;

		vst[i]=1;

		flag[i]=0;

		dfs(i, 0);

	}

	if(ok) {puts("-1"); return 0;}

	for(i=0; i<2; i++){

		cout<<nn[i]<<endl;

		for(j=0; j<nn[i]; j++){

			cout<<ans[i][j]<<' ';

		}

		cout<<endl;

	}

	return 0;

}


#include<bits/stdc++.h>

#define NN 100010

using namespace std;

vector<int> adj[NN];

int vst[NN],deg[NN],sg,tag[NN],line1[NN],line2[NN];

void dfs(int u,int tg){

	vst[u]=1;

	for(int i=0;i<deg[u];i++){

		int v=adj[u][i];

		if(vst[v]){

			if(tag[v]==tg)	sg=0;

			continue;

		}

		vst[v]=1;

		tag[v]=tg^1;

		dfs(v,tag[v]);

	}

}

int main(){

	int n,m,u,v,tg=0,size1,size2;

	scanf("%d%d",&n,&m);

	for(int i=1;i<=m;i++){

		scanf("%d %d",&u,&v);

		adj[u].push_back(v);	deg[u]++;

		adj[v].push_back(u);	deg[v]++;

	}

	sg=1;

	for(int i=1;sg && i<=n;i++){

		if(vst[i]) continue;

		dfs(i,0);

	}

	if(sg==0) printf("-1\n");

	else{

		size1=size2=0;

		for(int i=1;i<=n;i++){

			if(tag[i]==1) line1[size1++]=i;

			else line2[size2++]=i;

		}

		printf("%d\n",size1);

		printf("%d\n",size2);

		for(int i=0;i<size1;i++) printf("%d ",line1[i]);

		printf("\n");

		for(int i=0;i<size2;i++) printf("%d ",line2[i]);

	}

	return 0;

}


#include<bits/stdc++.h>

#define NN 111111

using namespace std;

vector<int> adj[NN];

int flag[NN], nn[2], ans[2][NN], ok;

void dfs(int u, int st){

	int beg=nn[1-st];

	for(int i=0; i<adj[u].size(); i++){

		if(flag[adj[u][i]]==st) {ok=1; return ;}

		if(flag[adj[u][i]]!=-1) continue;

		ans[1-st][nn[1-st]++]=adj[u][i];

		flag[adj[u][i]]=1-st;

	}

	for(int i=beg; i<nn[1-st]; i++){

		dfs(ans[1-st][i], 1-st);

	}

}

int main(){

	memset(flag, -1, sizeof(flag));

	int n,m,i,j,u,v;

	cin>>n>>m;

	for(i=0; i<m; i++){

		cin>>u>>v;

		adj[u].push_back(v);

		adj[v].push_back(u);

	}

	flag[1]=0;

	ans[0][nn[0]++]=1;

	dfs(1, 0);

	if(ok) {puts("-1"); return 0;}

	for(i=0; i<2; i++){

		cout<<nn[i]<<endl;

		for(j=0; j<nn[i]; j++){

			cout<<ans[i][j]<<' ';

		}

		cout<<endl;

	}

	return 0;

}


#include <bits/stdc++.h>

#define NN 100010

using namespace std;

typedef long long INT;

typedef pair <int, int> pii;

vector <int> s[2];

vector <int> adj[NN];

int col[NN];

bool dfs(int u, int fa=0, int c=0){

	col[u]=c;

	s[c].push_back(u);

	for(int i=adj[u].size(); i--; ){

		int v=adj[u][i];

		if(v==fa) continue;

		if(col[v]>=0){

			if(col[v]==c) return false;

			continue;

		}

		if(!dfs(v, u, !c)) return false;

	}

	return true;

}

int main (){

	int N, M, u, v;

	cin >> N >> M;

	for(int i=0; i<M; i++){

		scanf("%d %d", &u, &v);

		adj[u].push_back(v);

		adj[v].push_back(u);

	}

	memset(col, -1, sizeof(col));

	int c=0;

	for(int i=1; i<=N; i++){

		if(col[i]>=0) continue;

		if(!dfs(i, 0, c)){

			puts("-1");

			return 0;

		}

		c=!c;

	}

	for(int i=0; i<2; i++){

		printf("%d\n", s[i].size());

		for(int j=0; j<s[i].size(); j++) printf("%d ", s[i][j]);

		if(s[i].size()) puts("");

	}

	return 0;

}


#include<bits/stdc++.h>

#define NN 100010

using namespace std;

vector<int> adj[NN];

int vst[NN],deg[NN],sg,tag[NN],line1[NN],line2[NN];

void dfs(int u,int tg){

	vst[u]=1;

	for(int i=0;i<deg[u];i++){

		int v=adj[u][i];

		if(vst[v]){

			if(tag[v]==tg)	sg=0;

			continue;

		}

		vst[v]=1;

		tag[v]=-tg;;

		dfs(v,tag[v]);

	}

}

int main(){

	int n,m,u,v,tg=0,size1,size2;

	scanf("%d%d",&n,&m);

	for(int i=1;i<=m;i++){

		scanf("%d %d",&u,&v);

		adj[u].push_back(v);	deg[u]++;

		adj[v].push_back(u);	deg[v]++;

	}

	sg=1;

	tag[1]=1;

	for(int i=1;sg && i<=n;i++){

		if(vst[i]) continue;

		dfs(i,1);

	}

	if(sg==0) printf("-1\n");

	else{

		size1=size2=0;

		for(int i=1;i<=n;i++){

			if(tag[i]>0) line1[size1++]=i;

			if(tag[i]<0) line2[size2++]=i;

		}

		printf("%d\n",size1);

		printf("%d\n",size2);

		for(int i=0;i<size1;i++) printf("%d ",line1[i]);

		printf("\n");

		for(int i=0;i<size2;i++) printf("%d ",line2[i]);

	}

	return 0;

}


#include <bits/stdc++.h>

#define NN 100010

#define inf 0x3f3f3f3f

#define mod 1000000007

using namespace std;

typedef long long INT;

int fr[NN], se[NN], vst[NN], pp[NN], qq[NN];

vector<int> L[5], adj[NN];

int ok;

int dfs(int u, int pa=-1, int flag=0){

	int i, v;

	vst[u]=1;

	L[flag].push_back(u);

	for(int i=adj[u].size(); i--;){

		int v=adj[u][i];

		if(v==pa) continue;

		if(vst[v]) {ok=1;return 0;}

		dfs(v, u, 1-flag);

	}

	return 0;

}

int main(){

	int N, M, u, v;

	cin>>N>>M;

	for(int i=0; i<M; i++){

		scanf("%d%d", &u, &v);

		u--, v--;

		adj[u].push_back(v);

		adj[v].push_back(u);

		fr[i]=u, se[i]=v;

	}

	for(int i=0; i<N; i++){

		if(vst[i]) continue;

		dfs(i);

	}

	if(ok){

		puts("-1");

		return 0;

	}

	int m=L[0].size(), n=L[1].size();

	if(m==0 || n==0) ok=1;

	for(int i=0; i<m; i++){

		int u=L[0][i];

		pp[u]=1;

	}

	for(int i=0; i<n; i++){

		int u=L[1][i];

		qq[u]=1;

	}

	for(int i=0; i<M; i++){

		u=fr[i];

		v=se[i];

		if(pp[u]==0 && pp[v]==0) ok=1;

		if(qq[u]==0 && qq[v]==0) ok=1;

	}

	if(ok){

		puts("-1");

		return 0;

	}

	cout<<m<<endl;

	for(int i=0; i<m; i++) {

		if(i) cout<<" ";

		cout<<L[0][i]+1;

	}

	cout<<endl;

	cout<<n<<endl;

	for(int i=0; i<n; i++){

		if(i) cout<<" ";

		cout<<L[1][i]+1;

	}

	cout<<endl;

}


#include<bits/stdc++.h>

using namespace std;

#define MM 110000

vector<int>adj[MM];

int f,vis[MM],st[MM],ed[MM],stot,etot;

void dfs(int u,int pr,int ff)

{

	vis[u]=ff;

	for(int i=0;i<adj[u].size();i++){

		int v=adj[u][i];

		if(v==pr)continue;

		if(vis[v]==3-ff){f=1;return;}

		dfs(v,u,3-ff);

	}

}

int main()

{

//	freopen("in.txt","r",stdin);

	int n,m,u,v;

	scanf("%d%d",&n,&m);

	while(m--){

		scanf("%d%d",&u,&v);

		adj[u].push_back(v); adj[v].push_back(u);

	}

	f=0;  memset(vis,0,sizeof(vis));

	stot=0; etot=0;

	for(int i=1;i<=n;i++){

		if(vis[i] || adj[i].size()==0)continue;

		dfs(i,-1,1);

	}

	if(f)puts("-1");

	else{

		for(int i=1;i<=n;i++){

			if(vis[i]==1)st[stot++]=i;

			else if(vis[i]==2)ed[etot++]=i;

		}

		cout<<stot<<endl;

		for(int i=0;i<stot;i++)cout<<st[i]<<" ";

		cout<<endl<<etot<<endl;

		for(int i=0;i<etot;i++)cout<<ed[i]<<" ";

	}

	return 0;

}


#include <bits/stdc++.h>

#define NN 100010

#define inf 0x3f3f3f3f

#define mod 1000000007

using namespace std;

typedef long long INT;

int fr[NN], se[NN], vst[NN], pp[NN], qq[NN];

vector<int> L[5], adj[NN];

int ok;

int dfs(int u, int pa, int flag){

	int i, v;

	vst[u]=1;

	L[flag].push_back(u);

	for(int i=adj[u].size(); i--;){

		int v=adj[u][i];

		if(v==pa) continue;

		if(vst[v]) {ok=1;return 0;}

		dfs(v, u, 1-flag);

	}

	return 0;

}

int main(){

	int N, M, u, v;

	cin>>N>>M;

	for(int i=0; i<M; i++){

		scanf("%d%d", &u, &v);

		u--, v--;

		adj[u].push_back(v);

		adj[v].push_back(u);

		fr[i]=u, se[i]=v;

	}

	int jj=0;

	for(int i=0; i<N; i++){

		if(vst[i]) continue;

		dfs(i, -1, jj);

		jj^=1;

	}

	if(ok){

		puts("-1");

		return 0;

	}

	int m=L[0].size(), n=L[1].size();

	if(m==0 || n==0) ok=1;

	for(int i=0; i<m; i++){

		int u=L[0][i];

		pp[u]=1;

	}

	for(int i=0; i<n; i++){

		int u=L[1][i];

		qq[u]=1;

	}

	for(int i=0; i<M; i++){

		u=fr[i];

		v=se[i];

		if(pp[u]==0 && pp[v]==0) ok=1;

		if(qq[u]==0 && qq[v]==0) ok=1;

	}

	if(ok){

		puts("-1");

		return 0;

	}

	cout<<m<<endl;

	for(int i=0; i<m; i++) {

		if(i) cout<<" ";

		cout<<L[0][i]+1;

	}

	cout<<endl;

	cout<<n<<endl;

	for(int i=0; i<n; i++){

		if(i) cout<<" ";

		cout<<L[1][i]+1;

	}

	cout<<endl;

}


#include <bits/stdc++.h>

#define x first

#define y second

#define eps 1e-8

#define pb push_back

#define mod 1000000007

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define bit(x, y) (((x)>>(y))&1)

#define bctz(x) (__builtin_ctz(x))

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctzl(x) (__builtin_ctzll(x))

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef vector<int> VI;

template<typename T, typename U> inline void smin(T &a, const U &b) {if(a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, const U &b) {if(a<b) a=b;}

template<typename T> inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<typename T> inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<typename T> inline void println(T x) {print(x), putchar('\n');}

template<typename T> inline void printsp(T x) {print(x), putchar(' ');}

template<class T, class T1> inline void print(T x, T1 y) {printsp(x), println(y);}

template<class T, class T1, class T2> inline void print(T x, T1 y, T2 z) {printsp(x), printsp(y), println(z);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=(INT)a*a%m) if (b&1) ans=(INT)ans*a%m;

	return ans;

}

const int N=100010;

VI adj[N],ans[3];

int vst[N];

void dfs(int u,int f){

	vst[u]=3-f;

	ans[f].pb(u);

	for(int i=0; i<adj[u].size(); i++) {

		int v=adj[u][i];

		if(vst[v]) continue;

		dfs(v,3-f);

	}

}

int main() {

#ifndef ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	int n,m;gn(n,m);

	for(int i=0; i<m; i++) {

		int u,v;gn(u,v);

		adj[u].pb(v);

		adj[v].pb(u);

	}

	for(int i=1; i<=n; i++) if(!vst[i]) dfs(i,1);

	for(int i=1; i<=n; i++) for(int j=0; j<adj[i].size(); j++) {

		int v=adj[i][j];

		if(vst[i]==vst[v]){

			puts("-1");

			return 0;

		}

	}

	println(ans[1].size());

	for(int i=0; i<ans[1].size(); i++) printsp(ans[1][i]);puts("");

	println(ans[2].size());

	for(int i=0; i<ans[2].size(); i++) printsp(ans[2][i]);

	return 0;

}


#include<bits/stdc++.h>

#define NN 100010

using namespace std;

vector<int> adj[NN];

int vst[NN],deg[NN],sg,tag[NN],line1[NN],line2[NN];

void dfs(int u,int tg){

	vst[u]=1;

	for(int i=0;i<deg[u];i++){

		int v=adj[u][i];

		if(vst[v]){

			if(tag[v]==tg)	sg=0;

			continue;

		}

		vst[v]=1;

		tag[v]=-tg;;

		dfs(v,tag[v]);

	}

}

int main(){

	int n,m,u,v,tg=0,size1,size2;

	scanf("%d%d",&n,&m);

	for(int i=1;i<=m;i++){

		scanf("%d %d",&u,&v);

		adj[u].push_back(v);	deg[u]++;

		adj[v].push_back(u);	deg[v]++;

	}

	sg=1;

	tag[1]=1;

	for(int i=1;sg && i<=n;i++){

		if(vst[i]) continue;

		dfs(i,1);

	}

	if(sg==0) printf("-1\n");

	else{

		size1=size2=0;

		for(int i=1;i<=n;i++){

			if(tag[i]<0) line1[size1++]=i;

			if(tag[i]>0) line2[size2++]=i;

		}

		printf("%d\n",size1);

		printf("%d\n",size2);

		for(int i=0;i<size1;i++) printf("%d ",line1[i]);

		printf("\n");

		for(int i=0;i<size2;i++) printf("%d ",line2[i]);

	}

	return 0;

}


#include<bits/stdc++.h>

#define NN 100010

using namespace std;

vector<int> adj[NN];

int o=1,p=0,vst[NN],flag[NN],sa[NN],sb[NN];

void dfs(int u,int o){

	int i,v;

	vst[u]=1;

	for(i=0;i<adj[u].size();i++){

		v=adj[u][i];

		if(vst[v]){

			if(flag[v]==o) p=1;

			continue;

		}

		flag[v]=0-o;

		dfs(v,0-o);

	}

}

int main(){

//	freopen("in.txt","r",stdin);

	int n,m,a,b,i,la=0,lb=0;

	scanf("%d%d",&n,&m);

	for(i=0;i<m;i++){

		scanf("%d%d",&a,&b);

		adj[a].push_back(b);

		adj[b].push_back(a);

	}

	for(i=1;i<=n;i++)

		if(vst[i]==0) flag[i]=1,dfs(i,o);

	if(p) puts("-1");

	else{

		for(i=1;i<=n;i++){

			if(flag[i]>0) sa[la++]=i;

			if(flag[i]<0) sb[lb++]=i;

		}

		printf("%d\n",la);

		for(i=0;i<la;i++) printf("%d ",sa[i]);

		printf("\n%d\n",lb);

		for(i=0;i<lb;i++) printf("%d ",sb[i]);

	}

	return 0;

}


#include<bits/stdc++.h>

using namespace std;

#define MM 110000

vector<int>adj[MM];

int f,vis[MM],st[MM],ed[MM],stot,etot;

void dfs(int u,int pr,int ff)

{

	vis[u]=ff;

	for(int i=0;i<adj[u].size();i++){

		int v=adj[u][i];

		if(v==pr)continue;

		if(vis[v]){f=1;return;}

		dfs(v,u,3-ff);

	}

}

int main()

{

//	freopen("in.txt","r",stdin);

	int n,m,u,v;

	scanf("%d%d",&n,&m);

	while(m--){

		scanf("%d%d",&u,&v);

		adj[u].push_back(v); adj[v].push_back(u);

	}

	f=0;  memset(vis,0,sizeof(vis));

	stot=0; etot=0;

	for(int i=1;i<=n;i++){

		if(vis[i] || adj[i].size()==0)continue;

		dfs(i,-1,1);

	}

	if(f)puts("-1");

	else{

		for(int i=1;i<=n;i++){

			if(vis[i]==1)st[stot++]=i;

			else if(vis[i]==2)ed[etot++]=i;

		}

		cout<<stot<<endl;

		for(int i=0;i<stot;i++)cout<<st[i]<<" ";

		cout<<endl<<etot<<endl;

		for(int i=0;i<etot;i++)cout<<ed[i]<<" ";

	}

	return 0;

}


#include<bits/stdc++.h>

using namespace std;

vector<int> adj[100010];

int ok ,vst[100010], tmp, flag[100010];

int deg[2], ans[2][100010];

void dfs( int u, int tmp ) {

	vst[u] = 1;

	for( int i = 0; i < adj[u].size(); i++) {

		int v = adj[u][i];

		if ( vst[v] ) {

			if ( flag[v] != tmp^1 ) ok = 0;

			continue;

		}

		flag[v] = tmp^1;

		dfs( v, tmp^1 );

	}

}

int main(){

	int n,m, a, b;

	scanf("%d%d",&n,&m);

	for(int i=0;i<m;i++){

		scanf("%d%d",&a,&b);

		adj[a].push_back(b);

		adj[b].push_back(a);

	}

	ok = 1;

	for( int i = 1; ok && i<= n; i++) {

		if ( vst[i] ) continue;

		dfs( i, 0 );

	}

	if ( ok == 0 ) puts("-1");

	else {

		deg[0] = deg[1] = 0;

		for( int i = 1; i<=n; i++) {

			if( flag[i] == 0 ) ans[0][deg[0]++] = i;

			else ans[1][deg[1]++] = i;

		}

		for( int x= 0; x <2; x ++){

			cout << deg[x] << endl;

			for( int i = 0; i< deg[x]; i++) cout << ans[x][i] << ' ';

			puts("");

		}

	}

	return 0;

}


#include <bits/stdc++.h>

#define NN 100010

using namespace std;

vector<int> adj[NN];

int id[NN];

int ok=1;

int dfs(int u, int pa=-1, int flag=1){

	id[u]=flag;

	for(int i=adj[u].size(); i--;){

		int v=adj[u][i];

		if(id[v]){

			if(id[v]==flag){ok=0;return 0;}

			continue;

		}

		dfs(v, u, 3-flag);

	}

	return 0;

}

int fr[NN], se[NN];

int main(){

	int N, M, u, v;

	cin>>N>>M;

	for(int i=0; i<M; i++){

		scanf("%d%d", &u, &v);

		u--, v--;

		adj[u].push_back(v);

		adj[v].push_back(u);

		fr[i]=u, se[i]=v;

	}

	for(int i=0; i<N; i++){

		if(id[i]) continue;

		dfs(i);

	}

	for(int i=0; i<M; i++){

		u=fr[i], v=se[i];

		if(id[u]==id[v]) ok=0;

	}

	if(!ok){

		puts("-1");

		return 0;

	}

	int m=0, n=0;

	for(int i=0; i<N; i++){

		m+=(id[i]==1);

		n+=(id[i]==2);

	}

	if(m==0 || n==0){

		puts("-1");

		return 0;

	}

	cout<<m<<endl;

	for(int i=0; i<N; i++) if(id[i]==1) cout<<i+1<<" ";

	cout<<endl<<n<<endl;

	for(int i=0; i<N; i++) if(id[i]==2) cout<<i+1<<" ";

	cout<<endl;

}


#include<bits/stdc++.h>

using namespace std;
const int MAXN = 500100;

int v[MAXN];
pair<int,int> grafo[MAXN] , q[MAXN];
bool are[MAXN];
int p[MAXN];

int pai[MAXN];
vector<int> vec[MAXN];

struct seg{
	seg *fe,*fd;
	int meio,l,r;
	pair<int,int> mex;

	seg(int x,int y){
		meio = (x + y) / 2;
		l = x , r = y;
		mex = {-1,0};

		if(l == r) return;

		fe = new seg(x,meio);
		fd = new seg(meio + 1,y);
	}

	void up(int pos,int novo){
		if(l == r){
			mex = {novo,l};
			return;
		}
		if(pos <= meio) fe->up(pos,novo);
		else fd->up(pos,novo);

		if(fe->mex.first >= fd->mex.first) mex = fe->mex;
		else mex = fd->mex;
	}

	pair<int,int> get(int a,int b){
		if(l >= a && r <= b) return mex;
		if(l > b || r < a) return {-1,0};

		pair<int,int> re = fe->get(a,b) , rd = fd->get(a,b);

		if(re.first >= rd.first) return re;
		return rd;
	}
};

int find(int x){
	if(pai[x] == x) return x;
	return pai[x] = find(pai[x]);
}

void join(int a,int b){
	a = find(a) , b = find(b);

	if(vec[a].size() >= vec[b].size()){
		for(int i = 0;i < vec[b].size();i++)
			vec[a].push_back(vec[b][i]);
		pai[b] = a;
	}
	else{
		for(int i = 0;i < vec[a].size();i++)
			vec[b].push_back(vec[a][i]);
		pai[a] = b;
	}
}

seg st(0,MAXN);

int main(){

	int n,m,Q;
	scanf("%d %d %d",&n,&m,&Q);

	for(int i = 1;i <= n;i++) scanf("%d",&v[i]) , pai[i] = i , vec[i].push_back(i);

	for(int i = 1;i <= m;i++) scanf("%d %d",&grafo[i].first,&grafo[i].second);

	if(n > 100) return 0;

	for(int i = 1;i <= Q;i++){
		scanf("%d %d",&q[i].first,&q[i].second);
		if(q[i].first == 2) are[q[i].second] = true;
	}

	for(int i = 1;i <= m;i++){
		if(are[i] == true) continue;
		int a = grafo[i].first , b = grafo[i].second;
		if(find(a) == find(b)) continue;
		join(a,b);
	}

	vector<pair<int,int>> res;

	for(int i = Q;i >= 1;i--){
		if(q[i].first == 1){
			int a = find(q[i].second);
			res.push_back({a,vec[a].size()});
			//cout << "// " << a << " " << vec[a].size() << endl;
		}
		else{
			int a = find(grafo[q[i].second].first) , b = find(grafo[q[i].second].second);
			if(a == b) continue;
			join(a,b);
		}

		//for(int j = 1;j <= n;j++) cout << "|| " << j << " " << find(j) << endl;
		//cout << endl;
	}

	for(int i = 1;i < n;i++){
		if(find(i) == find(i + 1)) continue;
		join(i,i + 1);
	}

	if(n > 100) return 0;

	int h = find(1);
	for(int i = 0;i < n;i++) p[vec[h][i]] = i + 1 , st.up(i + 1,v[vec[h][i]]); //,cout << "/ " << i + 1 << " " << vec[h][i] << endl;

	for(int i = (int) res.size() - 1;i >= 0;i--){
		pair<int,int> h = st.get(p[res[i].first],p[res[i].first] + res[i].second - 1);
		printf("%d\n",h.first);
		st.up(h.second,0);
	}

}


#include<bits/stdc++.h>

using namespace std;
const int MAXN = 500100;

int v[MAXN];
pair<int,int> grafo[MAXN] , q[MAXN];
bool are[MAXN];
int p[MAXN];

int pai[MAXN];
vector<int> vec[MAXN];

struct seg{
	seg *fe,*fd;
	int meio,l,r;
	pair<int,int> mex;

	seg(int x,int y){
		meio = (x + y) / 2;
		l = x , r = y;
		mex = {-1,0};

		if(l == r) return;

		fe = new seg(x,meio);
		fd = new seg(meio + 1,y);
	}

	void up(int pos,int novo){
		if(l == r){
			mex = {novo,l};
			return;
		}
		if(pos <= meio) fe->up(pos,novo);
		else fd->up(pos,novo);

		if(fe->mex.first >= fd->mex.first) mex = fe->mex;
		else mex = fd->mex;
	}

	pair<int,int> get(int a,int b){
		if(l >= a && r <= b) return mex;
		if(l > b || r < a) return {-1,0};

		pair<int,int> re = fe->get(a,b) , rd = fd->get(a,b);

		if(re.first >= rd.first) return re;
		return rd;
	}
};

int find(int x){
	if(pai[x] == x) return x;
	return pai[x] = find(pai[x]);
}

void join(int a,int b){
	a = find(a) , b = find(b);

	if(vec[a].size() >= vec[b].size()){
		for(int i = 0;i < vec[b].size();i++)
			vec[a].push_back(vec[b][i]);
		pai[b] = a;
	}
	else{
		for(int i = 0;i < vec[a].size();i++)
			vec[b].push_back(vec[a][i]);
		pai[a] = b;
	}
}

seg st(0,MAXN);

int main(){

	int n,m,Q;
	cin >> n >> m >> Q;

	for(int i = 1;i <= n;i++) cin >> v[i] , pai[i] = i , vec[i].push_back(i);

	for(int i = 1;i <= m;i++) cin >> grafo[i].first >> grafo[i].second;

	if(n > 100) return 0;

	for(int i = 1;i <= Q;i++){
		cin >> q[i].first >> q[i].second;
		if(q[i].first == 2) are[q[i].second] = true;
	}

	for(int i = 1;i <= m;i++){
		if(are[i] == true) continue;
		int a = grafo[i].first , b = grafo[i].second;
		if(find(a) == find(b)) continue;
		join(a,b);
	}

	vector<pair<int,int>> res;

	for(int i = Q;i >= 1;i--){
		if(q[i].first == 1){
			int a = find(q[i].second);
			res.push_back({a,vec[a].size()});
			//cout << "// " << a << " " << vec[a].size() << endl;
		}
		else{
			int a = find(grafo[q[i].second].first) , b = find(grafo[q[i].second].second);
			if(a == b) continue;
			join(a,b);
		}

		//for(int j = 1;j <= n;j++) cout << "|| " << j << " " << find(j) << endl;
		//cout << endl;
	}

	for(int i = 1;i < n;i++){
		if(find(i) == find(i + 1)) continue;
		join(i,i + 1);
	}

	if(n > 100) return 0;

	int h = find(1);
	for(int i = 0;i < n;i++) p[vec[h][i]] = i + 1 , st.up(i + 1,v[vec[h][i]]); //,cout << "/ " << i + 1 << " " << vec[h][i] << endl;

	for(int i = (int) res.size() - 1;i >= 0;i--){
		pair<int,int> h = st.get(p[res[i].first],p[res[i].first] + res[i].second - 1);
		cout << h.first << endl;
		st.up(h.second,0);
	}

}


#include<bits/stdc++.h>

using namespace std;
const int MAXN = 500100;

int v[MAXN];
pair<int,int> grafo[MAXN] , q[MAXN];
bool are[MAXN];
int p[MAXN];

int pai[MAXN];
vector<int> vec[MAXN];

struct seg{
	seg *fe,*fd;
	int meio,l,r;
	pair<int,int> mex;

	seg(int x,int y){
		meio = (x + y) / 2;
		l = x , r = y;
		mex = {-1,0};

		if(l == r) return;

		fe = new seg(x,meio);
		fd = new seg(meio + 1,y);
	}

	void up(int pos,int novo){
		if(l == r){
			mex = {novo,l};
			return;
		}
		if(pos <= meio) fe->up(pos,novo);
		else fd->up(pos,novo);

		if(fe->mex.first >= fd->mex.first) mex = fe->mex;
		else mex = fd->mex;
	}

	pair<int,int> get(int a,int b){
		if(l >= a && r <= b) return mex;
		if(l > b || r < a) return {-1,0};

		pair<int,int> re = fe->get(a,b) , rd = fd->get(a,b);

		if(re.first >= rd.first) return re;
		return rd;
	}
};

int find(int x){
	if(pai[x] == x) return x;
	return pai[x] = find(pai[x]);
}

void join(int a,int b){
	a = find(a) , b = find(b);

	if(vec[a].size() >= vec[b].size()){
		for(int i = 0;i < vec[b].size();i++)
			vec[a].push_back(vec[b][i]);
		pai[b] = a;
	}
	else{
		for(int i = 0;i < vec[a].size();i++)
			vec[b].push_back(vec[a][i]);
		pai[a] = b;
	}
}

seg st(0,MAXN);

int main(){

	int n,m,Q;
	cin >> n >> m >> Q;

	for(int i = 1;i <= n;i++) cin >> v[i] , pai[i] = i , vec[i].push_back(i);

	for(int i = 1;i <= m;i++) cin >> grafo[i].first >> grafo[i].second;

	for(int i = 1;i <= Q;i++){
		cin >> q[i].first >> q[i].second;
		if(q[i].first == 2) are[q[i].second] = true;
	}

	for(int i = 1;i <= m;i++){
		if(are[i] == true) continue;
		int a = grafo[i].first , b = grafo[i].second;
		if(find(a) == find(b)) continue;
		join(a,b);
	}

	vector<pair<int,int>> res;

	for(int i = Q;i >= 1;i--){
		if(q[i].first == 1){
			int a = find(q[i].second);
			res.push_back({a,vec[a].size()});
			//cout << "// " << a << " " << vec[a].size() << endl;
		}
		else{
			int a = find(grafo[q[i].second].first) , b = find(grafo[q[i].second].second);
			if(a == b) continue;
			join(a,b);
		}

		//for(int j = 1;j <= n;j++) cout << "|| " << j << " " << find(j) << endl;
		//cout << endl;
	}

	for(int i = 1;i < n;i++){
		if(find(i) == find(i + 1)) continue;
		join(i,i + 1);
	}

	if(n > 100) return 0;

	int h = find(1);
	for(int i = 0;i < n;i++) p[vec[h][i]] = i + 1 , st.up(i + 1,v[vec[h][i]]); //,cout << "/ " << i + 1 << " " << vec[h][i] << endl;

	for(int i = (int) res.size() - 1;i >= 0;i--){
		pair<int,int> h = st.get(p[res[i].first],p[res[i].first] + res[i].second - 1);
		cout << h.first << endl;
		st.up(h.second,0);
	}

}


#include<bits/stdc++.h>

using namespace std;
const int MAXN = 500100;

int v[MAXN];
pair<int,int> grafo[MAXN] , q[MAXN];
bool are[MAXN];
int p[MAXN];

int pai[MAXN];
vector<int> vec[MAXN];

struct seg{
	seg *fe,*fd;
	int meio,l,r;
	pair<int,int> mex;

	seg(int x,int y){
		meio = (x + y) / 2;
		l = x , r = y;
		mex = {-1,0};

		if(l == r) return;

		fe = new seg(x,meio);
		fd = new seg(meio + 1,y);
	}

	void up(int pos,int novo){
		if(l == r){
			mex = {novo,l};
			return;
		}
		if(pos <= meio) fe->up(pos,novo);
		else fd->up(pos,novo);

		if(fe->mex.first >= fd->mex.first) mex = fe->mex;
		else mex = fd->mex;
	}

	pair<int,int> get(int a,int b){
		if(l >= a && r <= b) return mex;
		if(l > b || r < a) return {-1,0};

		pair<int,int> re = fe->get(a,b) , rd = fd->get(a,b);

		if(re.first >= rd.first) return re;
		return rd;
	}
};

int find(int x){
	if(pai[x] == x) return x;
	return pai[x] = find(pai[x]);
}

void join(int a,int b){
	a = find(a) , b = find(b);

	if(vec[a].size() >= vec[b].size()){
		for(int i = 0;i < vec[b].size();i++)
			vec[a].push_back(vec[b][i]);
		pai[b] = a;
	}
	else{
		for(int i = 0;i < vec[a].size();i++)
			vec[b].push_back(vec[a][i]);
		pai[a] = b;
	}
}

seg st(0,MAXN);

int main(){

	int n,m,Q;
	scanf("%d %d %d",&n,&m,&Q);

	for(int i = 1;i <= n;i++) scanf("%d",&v[i]) , pai[i] = i , vec[i].push_back(i);

	for(int i = 1;i <= m;i++) scanf("%d %d",&grafo[i].first,&grafo[i].second);

	//if(n > 100) return 0;

	for(int i = 1;i <= Q;i++){
		scanf("%d %d",&q[i].first,&q[i].second);
		if(q[i].first == 2) are[q[i].second] = true;
	}

	for(int i = 1;i <= m;i++){
		if(are[i] == true) continue;
		int a = grafo[i].first , b = grafo[i].second;
		if(find(a) == find(b)) continue;
		join(a,b);
	}

	vector<pair<int,int>> res;

	for(int i = Q;i >= 1;i--){
		if(q[i].first == 1){
			int a = find(q[i].second);
			res.push_back({a,vec[a].size()});
			//cout << "// " << a << " " << vec[a].size() << endl;
		}
		else{
			int a = find(grafo[q[i].second].first) , b = find(grafo[q[i].second].second);
			if(a == b) continue;
			join(a,b);
		}

		//for(int j = 1;j <= n;j++) cout << "|| " << j << " " << find(j) << endl;
		//cout << endl;
	}

	for(int i = 1;i < n;i++){
		if(find(i) == find(i + 1)) continue;
		join(i,i + 1);
	}

	if(n > 100) return 0;

	int h = find(1);
	for(int i = 0;i < n;i++) p[vec[h][i]] = i + 1 , st.up(i + 1,v[vec[h][i]]); //,cout << "/ " << i + 1 << " " << vec[h][i] << endl;

	for(int i = (int) res.size() - 1;i >= 0;i--){
		pair<int,int> h = st.get(p[res[i].first],p[res[i].first] + res[i].second - 1);
		printf("%d\n",h.first);
		st.up(h.second,0);
	}

}


#include<bits/stdc++.h>

using namespace std;
const int MAXN = 500100;

int v[MAXN];
pair<int,int> grafo[MAXN] , q[MAXN];
bool are[MAXN];
int p[MAXN];

int pai[MAXN];
vector<int> vec[MAXN];

struct seg{
	seg *fe,*fd;
	int meio,l,r;
	pair<int,int> mex;

	seg(int x,int y){
		meio = (x + y) / 2;
		l = x , r = y;
		mex = {-1,0};

		if(l == r) return;

		fe = new seg(x,meio);
		fd = new seg(meio + 1,y);
	}

	void up(int pos,int novo){
		if(l == r){
			mex = {novo,l};
			return;
		}
		if(pos <= meio) fe->up(pos,novo);
		else fd->up(pos,novo);

		if(fe->mex.first >= fd->mex.first) mex = fe->mex;
		else mex = fd->mex;
	}

	pair<int,int> get(int a,int b){
		if(l >= a && r <= b) return mex;
		if(l > b || r < a) return {-1,0};

		pair<int,int> re = fe->get(a,b) , rd = fd->get(a,b);

		if(re.first >= rd.first) return re;
		return rd;
	}
};

int find(int x){
	if(pai[x] == x) return x;
	return pai[x] = find(pai[x]);
}

void join(int a,int b){
	a = find(a) , b = find(b);

	if(vec[a].size() >= vec[b].size()){
		for(int i = 0;i < vec[b].size();i++)
			vec[a].push_back(vec[b][i]);
		pai[b] = a;
	}
	else{
		for(int i = 0;i < vec[a].size();i++)
			vec[b].push_back(vec[a][i]);
		pai[a] = b;
	}
}

seg st(0,MAXN);

int main(){

	int n,m,Q;
	scanf("%d %d %d",&n,&m,&Q);

	for(int i = 1;i <= n;i++) scanf("%d",&v[i]) , pai[i] = i , vec[i].push_back(i);

	for(int i = 1;i <= m;i++) scanf("%d %d",&grafo[i].first,&grafo[i].second);

	//if(n > 100) return 0;

	for(int i = 1;i <= Q;i++){
		scanf("%d %d",&q[i].first,&q[i].second);
		if(q[i].first == 2) are[q[i].second] = true;
	}

	for(int i = 1;i <= m;i++){
		if(are[i] == true) continue;
		int a = grafo[i].first , b = grafo[i].second;
		if(find(a) == find(b)) continue;
		join(a,b);
	}

	vector<pair<int,int>> res;

	for(int i = Q;i >= 1;i--){
		if(q[i].first == 1){
			int a = find(q[i].second);
			res.push_back({a,vec[a].size()});
			//cout << "// " << a << " " << vec[a].size() << endl;
		}
		else{
			int a = find(grafo[q[i].second].first) , b = find(grafo[q[i].second].second);
			if(a == b) continue;
			join(a,b);
		}

		//for(int j = 1;j <= n;j++) cout << "|| " << j << " " << find(j) << endl;
		//cout << endl;
	}

	for(int i = 1;i < n;i++){
		if(find(i) == find(i + 1)) continue;
		join(i,i + 1);
	}

	//if(n > 100) return 0;

	int h = find(1);
	for(int i = 0;i < n;i++) p[vec[h][i]] = i + 1 , st.up(i + 1,v[vec[h][i]]); //,cout << "/ " << i + 1 << " " << vec[h][i] << endl;

	for(int i = (int) res.size() - 1;i >= 0;i--){
		pair<int,int> h = st.get(p[res[i].first],p[res[i].first] + res[i].second - 1);
		printf("%d\n",h.first);
		st.up(h.second,0);
	}

}


#include<bits/stdc++.h>

using namespace std;
const int MAXN = 500100;

int v[MAXN];
pair<int,int> grafo[MAXN] , q[MAXN];
bool are[MAXN];
int p[MAXN];

int pai[MAXN];
vector<int> vec[MAXN];

struct seg{
	seg *fe,*fd;
	int meio,l,r;
	pair<int,int> mex;

	seg(int x,int y){
		meio = (x + y) / 2;
		l = x , r = y;
		mex = {-1,0};

		if(l == r) return;

		fe = new seg(x,meio);
		fd = new seg(meio + 1,y);
	}

	void up(int pos,int novo){
		if(l == r){
			mex = {novo,l};
			return;
		}
		if(pos <= meio) fe->up(pos,novo);
		else fd->up(pos,novo);

		if(fe->mex.first >= fd->mex.first) mex = fe->mex;
		else mex = fd->mex;
	}

	pair<int,int> get(int a,int b){
		if(l >= a && r <= b) return mex;
		if(l > b || r < a) return {-1,0};

		pair<int,int> re = fe->get(a,b) , rd = fd->get(a,b);

		if(re.first >= rd.first) return re;
		return rd;
	}
};

int find(int x){
	if(pai[x] == x) return x;
	return pai[x] = find(pai[x]);
}

void join(int a,int b){
	a = find(a) , b = find(b);

	if(vec[a].size() >= vec[b].size()){
		for(int i = 0;i < vec[b].size();i++)
			vec[a].push_back(vec[b][i]);
		pai[b] = a;
	}
	else{
		for(int i = 0;i < vec[a].size();i++)
			vec[b].push_back(vec[a][i]);
		pai[a] = b;
	}
}

seg st(0,MAXN);

int main(){

	int n,m,Q;
	cin >> n >> m >> Q;

	for(int i = 1;i <= n;i++) cin >> v[i] , pai[i] = i , vec[i].push_back(i);

	for(int i = 1;i <= m;i++) cin >> grafo[i].first >> grafo[i].second;

	for(int i = 1;i <= Q;i++){
		cin >> q[i].first >> q[i].second;
		if(q[i].first == 2) are[q[i].second] = true;
	}

	for(int i = 1;i <= m;i++){
		if(are[i] == true) continue;
		int a = grafo[i].first , b = grafo[i].second;
		if(find(a) == find(b)) continue;
		join(a,b);
	}

	vector<pair<int,int>> res;

	for(int i = Q;i >= 1;i--){
		if(q[i].first == 1){
			int a = find(q[i].second);
			res.push_back({a,vec[a].size()});
			//cout << "// " << a << " " << vec[a].size() << endl;
		}
		else{
			int a = find(grafo[q[i].second].first) , b = find(grafo[q[i].second].second);
			if(a == b) continue;
			join(a,b);
		}

		//for(int j = 1;j <= n;j++) cout << "|| " << j << " " << find(j) << endl;
		//cout << endl;
	}

	for(int i = 1;i < n;i++){
		if(find(i) == find(i + 1)) continue;
		join(i,i + 1);
	}

	int h = find(1);
	for(int i = 0;i < n;i++) p[vec[h][i]] = i + 1 , st.up(i + 1,v[vec[h][i]]); //,cout << "/ " << i + 1 << " " << vec[h][i] << endl;

	for(int i = (int) res.size() - 1;i >= 0;i--){
		pair<int,int> h = st.get(p[res[i].first],p[res[i].first] + res[i].second - 1);
		cout << h.first << endl;
		st.up(h.second,0);
	}

}