#include <cstdlib>
#include <iostream>

#define foru(i,n) for(int i = 0; i < (n); i++)

using namespace std;
string a,b;
int n1, n2, p, c;
int main(int argc, char *argv[])
{
   //freopen("input.txt","r",stdin);
   //freopen("output.txt","w",stdout);
   // 49 48
   cin >> a >> b;
   if (a.size() != b.size()) { cout << "NO";  return 1;}
   //if (a == b) {cout << "YES"; return 1;}
   foru(i,a.size()-1){
      /// xor 1 1 = 00

      p = (a[i]-48) ^ (a[i+1]-48);
      c = (a[i]-48) | (a[i+1]-48);
      if (a == b) {cout << "YES"; return 1;}
      if (b[i] == char(p+48))
         if (b[i+1] == char(c+48))
            {
                    a[i] = p+48;
                    a[i+1] = c+48;
            }
         else { cout << "NO";  return 1;}
      else if (b[i] == char(c+48))
              if (b[i+1] == char(p+48))
                 {
                    a[i] = c+48;
                    a[i+1] = p+48;
                 }
               else { cout << "NO";  return 1;}
     else { cout << "NO";  return 1;}
   }
   cout << "YES";

   return EXIT_SUCCESS;
}


#include <cstdlib>
#include <iostream>

#define foru(i,n) for(int i = 0; i < (n); i++)

using namespace std;
string a,b;
int n1, n2, p, c;
int main(int argc, char *argv[])
{
   //freopen("input.txt","r",stdin);
   //freopen("output.txt","w",stdout);
   // 49 48
   cin >> a >> b;
   if (a.size() != b.size()) { cout << "NO";  return 1;}
   if (a == b) {cout << "YES"; return 1;}
   foru(i,a.size()-1){
      /// xor 1 1 = 00

      p = (a[i]-48) ^ (a[i+1]-48);
      c = (a[i]-48) | (a[i+1]-48);
      if (b[i] == char(p+48))
         if (b[i+1] == char(c+48))
            {
                    a[i] = p+48;
                    a[i+1] = c+48;
            }
         else { cout << "NO";  return 1;}
      else if (b[i] == char(c+48))
              if (b[i+1] == char(p+48))
                 {
                    a[i] = c+48;
                    a[i+1] = p+48;
                 }
               else { cout << "NO";  return 1;}
     else { cout << "NO";  return 1;}
   }
   cout << "YES";

   return EXIT_SUCCESS;
}


#include <cstdlib>
#include <iostream>

#define foru(i,n) for(int i = 0; i < (n); i++)

using namespace std;
string a,b;
int n1, n2, p, c;
int main(int argc, char *argv[])
{
   //freopen("input.txt","r",stdin);
   //freopen("output.txt","w",stdout);
   // 49 48
   cin >> a >> b;
   if (a.size() != b.size()) { cout << "NO";  return 1;}
   foru(i,a.size()-1){
      /// xor 1 1 = 0

      p = (a[i]-48) ^ (a[i+1]-48);
      c = (a[i]-48) | (a[i+1]-48);
      if (b[i] == char(p+48))
         if (b[i+1] == char(c+48))
            {
                    a[i] = p;
                    a[i+1] = c;
            }
         else { cout << "NO";  return 1;}
      else if (b[i] == char(c+48))
              if (b[i+1] == char(p+48))
                 {
                    a[i] = c;
                    a[i+1] = p;
                 }
               else { cout << "NO";  return 1;}
     else { cout << "NO";  return 1;}
   }
   cout << "YES";

   return EXIT_SUCCESS;
}


#include <cstdlib>
#include <iostream>

#define foru(i,n) for(int i = 0; i < (n); i++)

using namespace std;
string a,b;
int n1, n2, p, c;
int main(int argc, char *argv[])
{
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
   // 49 48
   cin >> a >> b;
   if (a.size() != b.size()) { cout << "NO";  return 1;}
   //if (a == b) {cout << "YES"; return 1;}
   foru(i,a.size()-1){
      /// xor 1 1 = 00

      p = (a[i]-48) ^ (a[i+1]-48);
      c = (a[i]-48) | (a[i+1]-48);
      if (a == b) {cout << "YES"; return 1;}
      if (b[i] == char(p+48))
         if (b[i+1] == char(c+48))
            {
                    a[i] = p+48;
                    a[i+1] = c+48;
            }
         else { cout << "NO";  return 1;}
      else if (b[i] == char(c+48))
              if (b[i+1] == char(p+48))
                 {
                    a[i] = c+48;
                    a[i+1] = p+48;
                 }
               else { cout << "NO";  return 1;}
     else { cout << "NO";  return 1;}
   }
   cout << "YES";

   return EXIT_SUCCESS;
}


#include <cstdlib>
#include <iostream>

#define foru(i,n) for(int i = 0; i < (n); i++)

using namespace std;
string a,b;
int n1, n2, p, c;
int main(int argc, char *argv[])
{
   //freopen("input.txt","r",stdin);
   //freopen("output.txt","w",stdout);
   // 49 48
   cin >> a >> b;
   if (a.size() != b.size()) { cout << "NO";  return 1;}
   if (a == b) {cout << "YES"; return 1;}
   foru(i,a.size()-1){
      /// xor 1 1 = 0

      p = (a[i]-48) ^ (a[i+1]-48);
      c = (a[i]-48) | (a[i+1]-48);
      if (b[i] == char(p+48))
         if (b[i+1] == char(c+48))
            {
                    a[i] = p;
                    a[i+1] = c;
            }
         else { cout << "NO";  return 1;}
      else if (b[i] == char(c+48))
              if (b[i+1] == char(p+48))
                 {
                    a[i] = c;
                    a[i+1] = p;
                 }
               else { cout << "NO";  return 1;}
     else { cout << "NO";  return 1;}
   }
   cout << "YES";

   return EXIT_SUCCESS;
}


#include <stdio.h>
#include <string.h>
char s[1000005],t[1000005];
int main()
{
    int len,i,ok1,ok2;
    ok1=ok2 = 0;
    scanf("%s%s",s,t);
    len = strlen(s);
    if(len!=strlen(t))
    {
        printf("NO");
        return 0;
    }
    for(i=0;i<len;i++)  if(s[i]=='1') ok1 = 1;
    for(i=0;i<len;i++)  if(t[i]=='1') ok2 = 1;
    if((ok1&&ok2) || (!ok1&&!ok2))
        printf("YES");
    else
        printf("NO");
}


#include <stdio.h>
#include <string.h>
char s[1000005],t[1000005];
int main()
{
	int len,i,ok1,ok2;
	ok1=ok2 = 0;
	scanf("%s%s",s,t);
	len = strlen(s);
	if(len!=strlen(t))
	{
		printf("NO");
		return 0;
	}
	for(i=0;i<len;i++)	if(s[i]=='1') ok1 = 1;
	for(i=0;i<len;i++)	if(t[i]=='1') ok2 = 1;
	if((ok1&&ok2) || (!ok1&&ok2))
		printf("YES");
	else
		printf("NO");
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
#define max(a,b) (a>b?a:b)
#define min(a,b) (a>b?b:a)
using namespace std;

const int maxn = 1000005;
char a[maxn],b[maxn];
int dp[maxn],vis[3];
int main()
{
    int i,x,y;
    scanf("%s%s",a,b);
    int len=strlen(a);
    if(len!=strlen(b))
    {
        printf("NO\n");
        return 0;
    }
    if(a[0]==b[0])
        dp[0]=1;
    else
        dp[0]=0;
    for(i=0;i<len;i++)
    {
        if(i>=1)
            if(dp[i-1]&&a[i]==b[i])
                dp[i] = 1;
        if(i>=2)
        if(dp[i-2])
        {
            vis[0]=vis[1]=0;
            x=(a[i]-'0')^(a[i-1]-'0');
            y=(a[i]-'0')|(a[i-1]-'0');
            vis[x]=vis[y]=1;
            if(vis[b[i]-'0']&&vis[b[i]-'0'])
                dp[i]=1;
        }
        else if(!dp[i])
        {
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");
}


a=raw_input()
b=raw_input()
print'YES'if len(a)==len(b)and(a.count('1')>0)==(b.count('1')>0)else'NO'


#include<cstdio>
#include<iostream>
#include<queue>
#include<vector>
#include<map>
#include<utility>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<set>
using namespace std;
int main(int argc, const char *argv[])
{
  string a,b;
  cin>>a>>b;
  int lena=a.size(),lenb=b.size();
  if(lena!=lenb){cout<<"NO";return 0;}
  if(lena==1){cout<<(a[0]==b[0])?"YES":"NO";return 0;}
  bool a1=false,b1=false;
  int count=0;
  for(int i=0;i<lena;i++)if(a[i]=='0')count++;
  if(count==lena)a1=true;
  count=0;
  for(int i=0;i<lena;i++)if(b[i]=='0')count++;
  if(count==lena)b1=true;
  if(a1^b1)cout<<"NO";
  else cout<<"YES";
  return 0;
}


#include<cstdio>
#include<iostream>
#include<queue>
#include<vector>
#include<map>
#include<utility>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<set>
using namespace std;
int main(int argc, const char *argv[])
{
  string a,b;
  cin>>a>>b;
  int lena=a.size(),lenb=b.size();
  if(lena==1||lena!=lenb||lenb==1){cout<<"NO";return 0;}
  bool a1=false,b1=false;
  int count=0;
  for(int i=0;i<lena;i++)if(a[i]=='0')count++;
  if(count==lena)a1=true;
  for(int i=0;i<lena;i++)if(b[i]=='0')count++;
  if(count==lena)b1=true;
  if((!a1&b1) | (a1&!b1))cout<<"YES";
  else cout<<"NO";
  return 0;
}


#include<cstdio>
#include<iostream>
#include<queue>
#include<vector>
#include<map>
#include<utility>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<set>
using namespace std;
int main(int argc, const char *argv[])
{
  string a,b;
  cin>>a>>b;
  int lena=a.size(),lenb=b.size();
  if(lena==1||lena!=lenb||lenb==1){cout<<"NO";return 0;}
  bool a1=false,b1=false;
  int count=0;
  for(int i=0;i<lena;i++)if(a[i]=='0')count++;
  if(count==lena)a1=true;
  for(int i=0;i<lena;i++)if(b[i]=='0')count++;
  if(count==lena)b1=true;
  if(!a1&b1 | a1&!b1)cout<<"YES";
  else cout<<"NO";
  return 0;
}


#include<cstdio>
#include<iostream>
#include<queue>
#include<vector>
#include<map>
#include<utility>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<set>
using namespace std;
int main(int argc, const char *argv[])
{
  string a,b;
  cin>>a>>b;
  int lena=a.size(),lenb=b.size();
  if(lena!=lenb){cout<<"NO";return 0;}
  if(lena==1)cout<<(a[0]==b[0])?"YES":"NO";
  bool a1=false,b1=false;
  int count=0;
  for(int i=0;i<lena;i++)if(a[i]=='0')count++;
  if(count==lena)a1=true;
  count=0;
  for(int i=0;i<lena;i++)if(b[i]=='0')count++;
  if(count==lena)b1=true;
  if(a1^b1)cout<<"NO";
  else cout<<"YES";
  return 0;
}


#include<cstdio>
#include<iostream>
#include<queue>
#include<vector>
#include<map>
#include<utility>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<set>
using namespace std;
int main(int argc, const char *argv[])
{
  string a,b;
  cin>>a>>b;
  int lena=a.size(),lenb=b.size();
  if(lena==1||lena!=lenb||lenb==1){cout<<"NO";return 0;}
  int i=0;
  for(i=0;i<lena;i++)if(a[i]=='0'&&a[i+1]=='0'&&b[i]=='0'&&b[i+1]=='0')continue;
  for(;i<lena-1;i++)
  {
    if((a[i]=='0'&&a[i+1]=='0')||(b[i]=='0'&&b[i+1]=='0')){cout<<"NO";return 0;}
  }
  cout<<"YES";
  return 0;
}


#include<cstdio>
#include<iostream>
#include<queue>
#include<vector>
#include<map>
#include<utility>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<set>
using namespace std;
int main(int argc, const char *argv[])
{
  string a,b;
  cin>>a>>b;
  int lena=a.size(),lenb=b.size();
  if(lena==1||lena!=lenb||lenb==1){cout<<"NO";return 0;}
  int i=0;
  for(i=0;i<lena-1;i++)if(!(a[i]=='0'&&a[i+1]=='0'&&b[i]=='0'&&b[i+1]=='0'))break;
  if(i<lena-1 && ((a[i]=='0'&&a[i+1]=='0')||(b[i]=='0'&&b[i+1]=='0'))){cout<<"NO";return 0;}
  cout<<"YES";
  return 0;
}


#include<cstdio>
#include<iostream>
#include<queue>
#include<vector>
#include<map>
#include<utility>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<set>
using namespace std;
int main(int argc, const char *argv[])
{
  string a,b;
  cin>>a>>b;
  int lena=a.size(),lenb=b.size();
  if(lena==1||lena!=lenb||lenb==1){cout<<"NO";return 0;}
  int i=0;
  for(i=0;i<lena;i++)if(!(a[i]=='0'&&a[i+1]=='0'&&b[i]=='0'&&b[i+1]=='0'))break;
  for(;i<lena-1;i++)
  {
    if(b[i]=='0'&&b[i+1]=='0'){cout<<"NO";return 0;}
  }
  cout<<"YES";
  return 0;
}


#include<cstdio>
#include<iostream>
#include<queue>
#include<vector>
#include<map>
#include<utility>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<set>
using namespace std;
int main(int argc, const char *argv[])
{
  string a,b;
  cin>>a>>b;
  int lena=a.size(),lenb=b.size();
  if(lena!=lenb){cout<<"NO";return 0;}
  if(lena==1){cout<<((a[0]==b[0])?"YES":"NO");return 0;}
  bool a1=false,b1=false;
  int count=0;
  for(int i=0;i<lena;i++)if(a[i]=='0')count++;
  if(count==lena)a1=true;
  count=0;
  for(int i=0;i<lena;i++)if(b[i]=='0')count++;
  if(count==lena)b1=true;
  if(a1^b1)cout<<"NO";
  else cout<<"YES";
  return 0;
}


#include<cstdio>
#include<iostream>
#include<queue>
#include<vector>
#include<map>
#include<utility>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<set>
using namespace std;
int main(int argc, const char *argv[])
{
  string a,b;
  cin>>a>>b;
  int lena=a.size(),lenb=b.size();
  if(lena==1||lena!=lenb||lenb==1){cout<<"NO";return 0;}
  bool a1=false,b1=false;
  int count=0;
  for(int i=0;i<lena;i++)if(a[i]=='0')count++;
  if(count==lena)a1=true;
  count=0;
  for(int i=0;i<lena;i++)if(b[i]=='0')count++;
  if(count==lena)b1=true;
  if(a1^b1)cout<<"YES";
  else cout<<"NO";
  return 0;
}


#include<cstdio>
#include<iostream>
#include<queue>
#include<vector>
#include<map>
#include<utility>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<set>
using namespace std;
int main(int argc, const char *argv[])
{
  string a,b;
  cin>>a>>b;
  int lena=a.size(),lenb=b.size();
  if(lena==1||lena!=lenb||lenb==1){cout<<"NO";return 0;}
  for(int i=0;i<lena-1;i++)
  {
    if(a[i]==b[i]&&a[i+1]==b[i+1])continue;
    if((a[i]=='0'&&a[i+1]=='0')||(b[i]=='0'&&b[i+1]=='0')){cout<<"NO";return 0;}
    a[i+1]=b[i+1];
  }
  cout<<"YES";
  return 0;
}


#include<cstdio>
#include<iostream>
#include<queue>
#include<vector>
#include<map>
#include<utility>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<set>
using namespace std;
int main(int argc, const char *argv[])
{
  string a,b;
  cin>>a>>b;
  int lena=a.size(),lenb=b.size();
  if(lena==1||lena!=lenb||lenb==1){cout<<"NO";return 0;}
  bool a1=false,b1=false;
  int count=0;
  for(int i=0;i<lena;i++)if(a[i]=='0')count++;
  if(count==lena)a1=true;
  count=0;
  for(int i=0;i<lena;i++)if(b[i]=='0')count++;
  if(count==lena)b1=true;
  if(a1^b1)cout<<"NO";
  else cout<<"YES";
  return 0;
}


#include<cstdio>
#include<iostream>
#include<queue>
#include<vector>
#include<map>
#include<utility>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<set>
using namespace std;
int main(int argc, const char *argv[])
{
  string a,b;
  cin>>a>>b;
  int lena=a.size(),lenb=b.size();
  if(lena==1||lena!=lenb||lenb==1){cout<<"NO";return 0;}
  int i=0;
  for(i=0;i<lena;i++)if(!(a[i]=='0'&&a[i+1]=='0'&&b[i]=='0'&&b[i+1]=='0'))break;
  for(;i<lena-1;i++)
  {
    if((a[i]=='0'&&a[i+1]=='0')||(b[i]=='0'&&b[i+1]=='0')){cout<<"NO";return 0;}
  }
  cout<<"YES";
  return 0;
}


#include<cstdio>
#include<iostream>
#include<queue>
#include<vector>
#include<map>
#include<utility>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<set>
using namespace std;
int main(int argc, const char *argv[])
{
  string a,b;
  cin>>a>>b;
  int lena=a.size(),lenb=b.size();
  if(lena==1||lena!=lenb||lenb==1){cout<<"NO";return 0;}
  for(int i=0;i<lena-1;i++)
  {
    if(a[i]==b[i]&&a[i+1]==b[i+1])continue;
    if((a[i]=='0'&&a[i+1]=='0')||(b[i]=='0'&&b[i+1]=='0')){cout<<"NO";return 0;}
  }
  cout<<"YES";
  return 0;
}


#include<cstdio>
#include<iostream>
#include<queue>
#include<vector>
#include<map>
#include<utility>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<set>
using namespace std;
int main(int argc, const char *argv[])
{
  string a,b;
  cin>>a>>b;
  int lena=a.size(),lenb=b.size();
  if(lena==1||lena!=lenb||lenb==1){cout<<"NO";return 0;}
  for(int i=0;i<lena-2;i++)
  {
    if(a[i]==b[i]&&a[i+1]==b[i+1])continue;

    if((a[i]=='0'&&a[i+1]=='1'&&b[i]=='1'&&b[i+1]=='1')){continue;}
    if((a[i]=='1'&&a[i+1]=='0'&&b[i]=='1'&&b[i+1]=='1')||(a[i]=='1'&&a[i+1]=='0'&&b[i]=='0'&&b[i+1]=='1')){a[i+1]='1';continue;}
    if((a[i]=='1'&&a[i+1]=='1'&&b[i]=='0'&&b[i+1]=='1')){continue;}
    cout<<"NO";return 0;
  }
  cout<<"YES";
  return 0;
}


#include<cstdio>
#include<iostream>
#include<queue>
#include<vector>
#include<map>
#include<utility>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<set>
using namespace std;
int main(int argc, const char *argv[])
{
  string a,b;
  cin>>a>>b;
  int lena=a.size(),lenb=b.size();
  if(lena==1||lena!=lenb||lenb==1){cout<<"NO";return 0;}
  for(int i=0;i<lena-1;i++)
  {
    if(a[i]==b[i]&&a[i+1]==b[i+1])continue;
    if((a[i]=='0'&&a[i+1]=='1'&&b[i]=='1'&&b[i+1]=='1')){continue;}
    if((a[i]=='1'&&a[i+1]=='0'&&b[i]=='1'&&b[i+1]=='1')||(a[i]=='1'&&a[i+1]=='0'&&b[i]=='0'&&b[i+1]=='1')){a[i+1]='1';continue;}
    if((a[i]=='1'&&a[i+1]=='1'&&b[i]=='0'&&b[i+1]=='1')){continue;}
    cout<<"NO";return 0;
  }
  cout<<"YES";
  return 0;
}


#include <iostream>
#include <set>
#include <cstring>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;

int main()
{
    string a = "",b = "";
    cin>>a>>b;
    string ans = "YES";
    if(a.length() == 1 ) ans = "NO";
    else{
            for(int i = 0;i < min(a.length(),b.length()) - 1;i++){
                 if(a[i] == '1'&& a[i+1]=='1' && b[i] != b[i+1]);
                 else if(a[i] == '0'&& a[i+1]=='0'&&b[i] == '0'&&b[i+1] == '0');
                 else if(a[i] != a[i+1]&&b[i] == '1'&&b[i+1] == '1');
                 else{
                        ans = "NO";
                        break;
                 }
            }
    }
    cout<<ans;
    return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

#define M 1000001

char a[M],b[M];

int main(){
    cin>>a>>b;
    int ok = 1;
    if(strlen(a) == strlen(b)){
       for(int i = 0;i < strlen(a);i++){
            if(a[i] == '0' && b[i] == '1'){
                 ok = 0;
                 break;
            }
       }
    }
    if(ok) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

#define M 1000001

char a[M],b[M];

int main(){
    cin>>a>>b;
    int ok = 0;
    if(strlen(a) != strlen(b));
    else{
       for(int i = 0;i < strlen(a);i++){
            if(a[i] == '1') ok = 1;
       }
    }
    if(ok) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


#include <iostream>
#include <set>
#include <cstring>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;

int main()
{
    string a = "",b = "";
    cin>>a>>b;
    string ans = "YES";
    if(a.length() == 1&&b.length()  > a.length()) ans = "NO";
    else{
            for(int i = 0;i < b.length() - 1;i++){
                if(a[i] == b[i] &&a[i+1] == b[i+1]);
                 else if(a[i] == '1'&& a[i+1]=='1' && b[i] != b[i+1]);
                 else if(a[i] == '0'&& a[i+1]=='0'&&b[i] == '0'&&b[i+1] == '0');
                 else if(a[i] != a[i+1]&&b[i] == '1'&&b[i+1] == '1');
                 else{
                        ans = "NO";
                        break;
                 }
            }
    }
    cout<<ans;
    return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

#define M 1000001

char a[M],b[M];

int main(){
    cin>>a>>b;
    int ok = 1;
    if(strlen(a) != strlen(b)) ok =0;
    else{
       for(int i = 0;i < strlen(a);i++){
            if(a[i] == '0' && b[i] == '1'){
                 ok = 0;
                 break;
            }
       }
    }
    if(ok) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


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

int n, m;
vector< vector<int> > gph;
vector<int> A;
vector<int> B;
int cor[100005];

bool dfs(int idx) {
    bool f = true;
    for(int i = 0; i < gph[idx].size(); i++) {
        if(cor[gph[idx][i]]) {
            if(cor[gph[idx][i]] == cor[idx])
                return false;
            continue;
        }
        else {
            if(cor[idx] == 1) {
                cor[gph[idx][i]] = 2;
                B.push_back(gph[idx][i]+1);
            }
            else {
                cor[gph[idx][i]] = 1;
                A.push_back(gph[idx][i]+1);
            }
        }
        f = f && dfs(gph[idx][i]);
    }

    return f;
}

int main() {
    cin >> n >> m;
    gph = vector< vector<int> >(n);

    for(int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        gph[x-1].push_back(y-1);
        gph[y-1].push_back(x-1);
    }

    cor[0] = 1;
    A.push_back(1);
    if(!dfs(0) || A.size() == 0 || B.size() == 0) {
        cout << "-1\n";
        return 0;
    }

    cout << A.size() << '\n';
    for(int i = 0; i < A.size(); i++)
        cout << A[i] << ' ';
    cout << '\n';

    cout << B.size() << '\n';
    for(int i = 0; i < B.size(); i++)
        cout << B[i] << ' ';
    cout << '\n';

    return 0;
}


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

int n, m;
vector< vector<int> > gph;
set<int> A;
set<int> B;
int cor[100005];

bool dfs(int idx) {
    vector<int> arr;
    bool f = true;
    for(int i = 0; i < gph[idx].size(); i++) {
        if(cor[gph[idx][i]]) {
            if(cor[gph[idx][i]] == cor[idx])
                return false;
            continue;
        }
        else {
            arr.push_back(gph[idx][i]);
            if(cor[idx] == 1) {
                cor[gph[idx][i]] = 2;
                B.insert(gph[idx][i]+1);
            }
            else {
                cor[gph[idx][i]] = 1;
                A.insert(gph[idx][i]+1);
            }
        }
    }

    for(int i = 0; i < arr.size(); i++)
	f = f && dfs(arr[i]);
    return f;
}

int main() {
    cin >> n >> m;
    gph = vector< vector<int> >(n);

    int first;

    for(int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        first = x;
        gph[x-1].push_back(y-1);
        gph[y-1].push_back(x-1);
    }

    cor[first-1] = 1;
    A.insert(first);
    if(!dfs(first-1) || A.size() == 0 || B.size() == 0) {
        cout << "-1\n";
        return 0;
    }

    cout << A.size() << '\n';
    for(set<int>::iterator it = A.begin(); it != A.end(); it++)
        cout << *it << ' ';
    cout << '\n';

    cout << B.size() << '\n';
    for(set<int>::iterator it = B.begin(); it != B.end(); it++)
        cout << *it << ' ';
    cout << '\n';

    return 0;
}


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

int n, m;
vector< vector<int> > gph;
set<int> A;
set<int> B;
int cor[100005];

bool dfs(int idx) {
    vector<int> arr;
    bool f = true;
    for(int i = 0; i < gph[idx].size(); i++) {
        if(cor[gph[idx][i]]) {
            if(cor[gph[idx][i]] == cor[idx])
                return false;
            continue;
        }
        else {
            arr.push_back(gph[idx][i]);
            if(cor[idx] == 1) {
                cor[gph[idx][i]] = 2;
                B.insert(gph[idx][i]+1);
            }
            else {
                cor[gph[idx][i]] = 1;
                A.insert(gph[idx][i]+1);
            }
        }
    }

    for(int i = 0; i < arr.size(); i++)
	f = f && dfs(arr[i]);
    return f;
}

int main() {
    cin >> n >> m;
    gph = vector< vector<int> >(n);

    int first;

    for(int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        first = x;
        gph[x-1].push_back(y-1);
        gph[y-1].push_back(x-1);
    }

    for(int i = 0; i < n; i++) {
        if(!cor[i]) {
            if(gph[i].empty()) continue;

            cor[i] = 1;
            A.insert(i+1);
     	    if(!dfs(i)) {
                cout << "-1\n";
                return 0;
            }
        }
    }

    cout << A.size() << '\n';
    for(set<int>::iterator it = A.begin(); it != A.end(); it++)
        cout << *it << ' ';
    cout << '\n';

    cout << B.size() << '\n';
    for(set<int>::iterator it = B.begin(); it != B.end(); it++)
        cout << *it << ' ';
    cout << '\n';

    return 0;
}


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

int n, m;
vector< vector<int> > gph;
set<int> A;
set<int> B;
int cor[100005];

bool dfs(int idx) {
    bool f = true;
    for(int i = 0; i < gph[idx].size(); i++) {
        if(cor[gph[idx][i]]) {
            if(cor[gph[idx][i]] == cor[idx])
                return false;
            continue;
        }
        else {
            if(cor[idx] == 1) {
                cor[gph[idx][i]] = 2;
                B.insert(gph[idx][i]+1);
            }
            else {
                cor[gph[idx][i]] = 1;
                A.insert(gph[idx][i]+1);
            }
        }
    }

    for(int i = 0; i < gph[idx].size(); i++)
	f = f && dfs(gph[idx][i]);
    return f;
}

int main() {
    cin >> n >> m;
    gph = vector< vector<int> >(n);

    int first;

    for(int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        first = x;
        gph[x-1].push_back(y-1);
        gph[y-1].push_back(x-1);
    }

    cor[first-1] = 1;
    A.insert(first);
    if(!dfs(first-1) || A.size() == 0 || B.size() == 0) {
        cout << "-1\n";
        return 0;
    }

    cout << A.size() << '\n';
    for(set<int>::iterator it = A.begin(); it != A.end(); it++)
        cout << *it << ' ';
    cout << '\n';

    cout << B.size() << '\n';
    for(set<int>::iterator it = B.begin(); it != B.end(); it++)
        cout << *it << ' ';
    cout << '\n';

    return 0;
}


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

int n, m;
vector< vector<int> > gph;
set<int> A;
set<int> B;
int cor[100005];

bool dfs(int idx) {
    vector<int> arr;
    bool f = true;
    for(int i = 0; i < gph[idx].size(); i++) {
        if(cor[gph[idx][i]]) {
            if(cor[gph[idx][i]] == cor[idx])
                return false;
            continue;
        }
        else {
            arr.push_back(gph[idx][i]);
            if(cor[idx] == 1) {
                cor[gph[idx][i]] = 2;
                B.insert(gph[idx][i]+1);
            }
            else {
                cor[gph[idx][i]] = 1;
                A.insert(gph[idx][i]+1);
            }
        }
    }

    for(int i = 0; i < arr.size(); i++)
	f = f && dfs(arr[i]);
    return f;
}

int main() {
    cin >> n >> m;
    gph = vector< vector<int> >(n);

    int first;

    for(int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        first = x;
        gph[x-1].push_back(y-1);
        gph[y-1].push_back(x-1);
    }

    for(int i = 0; i < n; i++) {
        if(!cor[i]) {
            if(gph[i].empty()) continue;
     	    if(!dfs(first-1) || A.size() == 0 || B.size() == 0) {
                cout << "-1\n";
                return 0;
            }
        }
    }

    cout << A.size() << '\n';
    for(set<int>::iterator it = A.begin(); it != A.end(); it++)
        cout << *it << ' ';
    cout << '\n';

    cout << B.size() << '\n';
    for(set<int>::iterator it = B.begin(); it != B.end(); it++)
        cout << *it << ' ';
    cout << '\n';

    return 0;
}


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

int n, m;
vector< vector<int> > gph;
set<int> A;
set<int> B;
int cor[100005];

bool dfs(int idx) {
    bool f = true;
    for(int i = 0; i < gph[idx].size(); i++) {
        if(cor[gph[idx][i]]) {
            if(cor[gph[idx][i]] == cor[idx])
                return false;
            continue;
        }
        else {
            if(cor[idx] == 1) {
                cor[gph[idx][i]] = 2;
                B.insert(gph[idx][i]+1);
            }
            else {
                cor[gph[idx][i]] = 1;
                A.insert(gph[idx][i]+1);
            }
        }
        f = f && dfs(gph[idx][i]);
    }

    return f;
}

int main() {
    cin >> n >> m;
    gph = vector< vector<int> >(n);

    int first;

    for(int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        first = x;
        gph[x-1].push_back(y-1);
        gph[y-1].push_back(x-1);
    }

    cor[first-1] = 1;
    A.insert(first);
    if(!dfs(first-1) || A.size() == 0 || B.size() == 0) {
        cout << "-1\n";
        return 0;
    }

    cout << A.size() << '\n';
    for(set<int>::iterator it = A.begin(); it != A.end(); it++)
        cout << *it << ' ';
    cout << '\n';

    cout << B.size() << '\n';
    for(set<int>::iterator it = B.begin(); it != B.end(); it++)
        cout << *it << ' ';
    cout << '\n';

    return 0;
}


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

int n, m;
vector< vector<int> > gph;
vector<int> A;
vector<int> B;
int cor[100005];

bool dfs(int idx) {
    bool f = true;
    for(int i = 0; i < gph[idx].size(); i++) {
        if(cor[gph[idx][i]]) {
            if(cor[gph[idx][i]] == cor[idx])
                return false;
            continue;
        }
        else {
            if(cor[idx] == 1) {
                cor[gph[idx][i]] = 2;
                B.push_back(gph[idx][i]+1);
            }
            else {
                cor[gph[idx][i]] = 1;
                A.push_back(gph[idx][i]+1);
            }
        }
        f = f && dfs(gph[idx][i]);
    }

    return f;
}

int main() {
    cin >> n >> m;
    gph = vector< vector<int> >(n);

    int first;

    for(int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        first = x;
        gph[x-1].push_back(y-1);
        gph[y-1].push_back(x-1);
    }

    cor[first-1] = 1;
    A.push_back(first);
    if(!dfs(first-1) || A.size() == 0 || B.size() == 0) {
        cout << "-1\n";
        return 0;
    }

    cout << A.size() << '\n';
    for(int i = 0; i < A.size(); i++)
        cout << A[i] << ' ';
    cout << '\n';

    cout << B.size() << '\n';
    for(int i = 0; i < B.size(); i++)
        cout << B[i] << ' ';
    cout << '\n';

    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <stack>
#include <queue>
#include <functional>
#include <vector>
#include <string>
#include <set>
#include <cstring>
#include <iomanip>
#include <cmath>
using namespace std;
#define ll long long
#define pb push_back
#define endl  '\n'
#define fora(x,y,z) for(int x=y;x<(z);x++)
#define PNL printf("\n")
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
#define MOD 1000000007
#define endl  '\n'
#define debug(x) cout<<"here"<<x<<endl;
#define MAX 100000
#define iosb ios_base::sync_with_stdio(false);cin.tie(0);
vector <int> a[MAX];
bool flag=false;
int cnt=0;
int clr[MAX];
void dfs(int u)
{
    if(clr[u]==1)
        cnt++;
    for(int i=0;i<a[u].size();i++)
    {
        int v=a[u][i];
        if(clr[v]==0)
        {
            if(clr[u]==1)
            {
                clr[v]=2;
                dfs(v);
            }
            else
            {
                clr[v]=1;
                dfs(v);
            }
        }
        else
            if(clr[u]==clr[v])
        {
            flag=1;
            return ;
        }
    }
}
int main(){
	iosb;
	int n,m;
	cin>>n>>m;
	int x,y;
	fora(i,0,m)
	{
	    cin>>x>>y;
	    a[x].pb(y);
	    a[y].pb(x);
	}
	for(int i=1;i<=n;i++)
    {
        if(!clr[i])
        {
            clr[i]=1;
            dfs(i);
            if(flag)
                break;
        }
    }
    if(flag)
        cout<<-1<<endl;
    else
    {
       cout<<cnt<<endl;
       for(int i=1;i<=cnt;i++)
        if(clr[i]==1)
        cout<<i<<" ";
        cout<<endl;
       cout<<n-cnt<<endl;
       for(int i=1;i<=cnt;i++)
        if(clr[i]==2)
        cout<<i<<" ";
       cout<<endl;
    }

	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <stack>
#include <queue>
#include <functional>
#include <vector>
#include <string>
#include <set>
#include <cstring>
#include <iomanip>
#include <cmath>
using namespace std;
#define ll long long
#define pb push_back
#define endl  '\n'
#define fora(x,y,z) for(int x=y;x<(z);x++)
#define PNL printf("\n")
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
#define MOD 1000000007
#define endl  '\n'
#define debug(x) cout<<"here"<<x<<endl;
#define MAX 100000
#define iosb ios_base::sync_with_stdio(false);cin.tie(0);
vector <int> a[MAX];
bool flag=false;
int cnt=0;
int clr[MAX];
vector <int> v1;
vector <int> v2;
void dfs(int u)
{
    for(int i=0;i<a[u].size();i++)
    {
        int v=a[u][i];
        if(clr[v]==0)
        {
            if(clr[u]==1)
            {
                clr[v]=2;
                v1.pb(v);
                dfs(v);
            }
            else
            {
                clr[v]=1;
                v2.pb(v);
                dfs(v);
            }
        }
        else
            if(clr[u]==clr[v])
        {
            flag=1;
            return ;
        }
    }
}
int main(){
	iosb;
	int n,m;
	cin>>n>>m;
	int x,y;
	fora(i,0,m)
	{
	    cin>>x>>y;
	    a[x].pb(y);
	    a[y].pb(x);
	}
	for(int i=1;i<=n;i++)
    {
        if(!clr[i])
        {
            clr[i]=1;
            v2.pb(i);
            dfs(i);
            if(flag)
                break;
        }
    }
    if(flag)
        cout<<-1<<endl;
    else
    {
       cout<<v1.size()<<endl;
       for(int i=0;i<v1.size();i++)
        cout<<v1[i]<<" ";
       cout<<endl;
       cout<<v2.size()<<endl;
       for(int i=0;i<v2.size();i++)
        cout<<v2[i]<<" ";
       cout<<endl;
    }

	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <stack>
#include <queue>
#include <functional>
#include <vector>
#include <string>
#include <set>
#include <cstring>
#include <iomanip>
#include <cmath>
using namespace std;
#define ll long long
#define pb push_back
#define endl  '\n'
#define fora(x,y,z) for(int x=y;x<(z);x++)
#define PNL printf("\n")
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
#define MOD 1000000007
#define endl  '\n'
#define debug(x) cout<<"here"<<x<<endl;
#define MAX 100000
#define iosb ios_base::sync_with_stdio(false);cin.tie(0);
vector <int> a[MAX];
int clr[MAX];
int main(){
	iosb;
	int n,m;
	cin>>n>>m;
	int x,y;
	fora(i,0,m)
	{
	    cin>>x>>y;
	    a[x].pb(y);
	    a[y].pb(x);
	}
	queue <int> q;
	int c=0;
	for(int i=1;i<=n;i++)
    {
        if(clr[i]==0)
        {
            q.push(i);
            clr[i]=1;
            while(!q.empty())
            {
                int u=q.front();
                q.pop();
                if(clr[u]==1)
                    c++;
                for(int i=0;i<a[u].size();i++)
                {
                    int v=a[u][i];
                    if(clr[v]==0)
                    {
                        if(clr[u]==1)
                        {
                            clr[v]=2;
                            q.push(v);
                        }
                        else
                        {
                            clr[v]=1;
                            q.push(v);
                        }
                    }
                    else
                        if(clr[u]==clr[v])
                    {
                        cout<<-1<<endl;
                        return 0;
                    }
                }
            }
        }
    }
    cout<<c<<endl;
    for(int i=1;i<=n;i++)
        if(clr[i]==1)
        cout<<i<<" ";
    cout<<endl;
    cout<<n-c<<endl;
    for(int i=1;i<=n;i++)
        if(clr[i]==2)
        cout<<i<<" ";
    cout<<endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <stack>
#include <queue>
#include <functional>
#include <vector>
#include <string>
#include <set>
#include <cstring>
#include <iomanip>
#include <cmath>
using namespace std;
#define ll long long
#define pb push_back
#define endl  '\n'
#define fora(x,y,z) for(int x=y;x<(z);x++)
#define PNL printf("\n")
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
#define MOD 1000000007
#define endl  '\n'
#define debug(x) cout<<"here"<<x<<endl;
#define MAX 1000
#define iosb ios_base::sync_with_stdio(false);cin.tie(0);
vector <int> a[MAX];
int clr[MAX];
int main(){
	iosb;
	int n,m;
	cin>>n>>m;
	int x,y;
	fora(i,0,m)
	{
	    cin>>x>>y;
	    a[x].pb(y);
	    a[y].pb(x);
	}
	queue <int> q;
	int c=0;
	for(int i=1;i<=n;i++)
    {
        if(clr[i]==0)
        {
            q.push(i);
            clr[i]=1;
            while(!q.empty())
            {
                int u=q.front();
                q.pop();
                if(clr[u]==1)
                    c++;
                for(int i=0;i<a[u].size();i++)
                {
                    int v=a[u][i];
                    if(clr[v]==0)
                    {
                        if(clr[u]==1)
                        {
                            clr[v]=2;
                            q.push(v);
                        }
                        else
                        {
                            clr[v]=1;
                            q.push(v);
                        }
                    }
                    else
                        if(clr[u]==clr[v])
                    {
                        cout<<-1<<endl;
                        return 0;
                    }
                }
            }
        }
    }
    cout<<c<<endl;
    for(int i=1;i<=n;i++)
        if(clr[i]==1)
        cout<<i<<" ";
    cout<<endl;
    cout<<n-c<<endl;
    for(int i=1;i<=n;i++)
        if(clr[i]==2)
        cout<<i<<" ";
    cout<<endl;
	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;
const int maxn=100000+10;
const int maxm=100000+10;
struct hh
{
  int v,next;
}e[maxm*2];
int n,m,point,l1,l2;
int head[maxn],used[maxn],ans1[maxn],ans2[maxn],dep[maxn];
template <class T> void read(T&x)
{
  x=0;char c=getchar();int f=0;
  while(c<'0'||c>'9'){f|=(c=='-');c=getchar();}
  while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();
  x=f?-x:x;
}
void add(int u,int v)
{
  e[++point].v=v;e[point].next=head[u];head[u]=point;
  e[++point].v=u;e[point].next=head[v];head[v]=point;
}
bool cmp(int a,int b){return a>b;}
void dfs(int x,int col,int de)
{
  used[x]=col;dep[x]=de;
  for(int i=head[x];~i;i=e[i].next)
  {
    int v=e[i].v;
    if(used[v]&&used[v]==used[i]&&dep[v]<x)
    {
      puts("-1");
      exit(0);
    }
    if(!dep[v])dfs(v,col==1?2:1,de+1);
  }
  return;
}
int main()
{
  memset(head,-1,sizeof(head));
  read(n);read(m);
  for(int i=1;i<=m;i++)
  {
    int u,v;
    read(u);read(v);
    add(u,v);
  }
  for(int i=1;i<=n;i++)if(!used[i])dfs(i,1,1);
  for(int i=1;i<=n;i++)used[i]==1?ans1[++l1]=i:ans2[++l2]=i;
  printf("%d\n",l1);
  for(int i=1;i<=l1;i++)
  {
    if(!l2&&head[ans1[i]]==-1)
    {
      ans2[++l2]=ans1[i];
      continue;
    }
    printf("%d ",ans1[i]);

  }
  printf("\n");
  printf("%d\n",l2);
  for(int i=1;i<=l2;i++)printf("%d ",ans2[i]);
  return 0;
}


#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;
const int maxn=100000+10;
const int maxm=100000+10;
struct hh
{
  int v,next;
}e[maxm*2];
int n,m,point,l1,l2;
int head[maxn],used[maxn],ans1[maxn],ans2[maxn],dep[maxn];
template <class T> void read(T&x)
{
  x=0;char c=getchar();int f=0;
  while(c<'0'||c>'9'){f|=(c=='-');c=getchar();}
  while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();
  x=f?-x:x;
}
void add(int u,int v)
{
  e[++point].v=v;e[point].next=head[u];head[u]=point;
  e[++point].v=u;e[point].next=head[v];head[v]=point;
}
bool cmp(int a,int b){return a>b;}
void dfs(int x,int col,int de)
{
  used[x]=col;dep[x]=de;
  for(int i=head[x];~i;i=e[i].next)
  {
    int v=e[i].v;
    if(used[v]&&used[v]==used[i]&&dep[v]<=x)
    {
      puts("-1");
      exit(0);
    }
    if(!dep[v])dfs(v,col==1?2:1,de+1);
  }
  return;
}
int main()
{
  memset(head,-1,sizeof(head));
  read(n);read(m);
  for(int i=1;i<=m;i++)
  {
    int u,v;
    read(u);read(v);
    add(u,v);
  }
  for(int i=1;i<=n;i++)if(!used[i])dfs(i,1,1);
  for(int i=1;i<=n;i++)used[i]==1?ans1[++l1]=i:ans2[++l2]=i;
  printf("%d\n",l1);
  for(int i=1;i<=l1;i++)printf("%d ",ans1[i]);
  printf("\n");
  printf("%d\n",l2);
  for(int i=1;i<=l2;i++)printf("%d ",ans2[i]);
  return 0;
}


#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;
const int maxn=100000+10;
const int maxm=100000+10;
struct hh
{
  int v,next;
}e[maxm*2];
int n,m,point,l1,l2;
int head[maxn],used[maxn],ans1[maxn],ans2[maxn],dep[maxn];
template <class T> void read(T&x)
{
  x=0;char c=getchar();int f=0;
  while(c<'0'||c>'9'){f|=(c=='-');c=getchar();}
  while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();
  x=f?-x:x;
}
void add(int u,int v)
{
  e[++point].v=v;e[point].next=head[u];head[u]=point;
  e[++point].v=u;e[point].next=head[v];head[v]=point;
}
bool cmp(int a,int b){return a>b;}
void dfs(int x,int col,int de)
{
  used[x]=col;dep[x]=de;
  for(int i=head[x];~i;i=e[i].next)
  {
    int v=e[i].v;
    if(used[v]&&used[v]==used[x]&&dep[v]<x)
    {
      puts("-1");
      exit(0);
    }
    if(!dep[v])dfs(v,col==1?2:1,de+1);
  }
  return;
}
int main()
{
  memset(head,-1,sizeof(head));
  read(n);read(m);
  for(int i=1;i<=m;i++)
  {
    int u,v;
    read(u);read(v);
    add(u,v);
  }
  for(int i=1;i<=n;i++)if(!used[i])dfs(i,1,1);
  for(int i=1;i<=n;i++)used[i]==1?ans1[++l1]=i:ans2[++l2]=i;
  printf("%d\n",l1);
  for(int i=1;i<=l1;i++)
  {
    if(!l2&&head[ans1[i]]==-1)
    {
      ans2[++l2]=ans1[i];
      continue;
    }
    printf("%d ",ans1[i]);

  }
  printf("\n");
  printf("%d\n",l2);
  for(int i=1;i<=l2;i++)printf("%d ",ans2[i]);
  return 0;
}


#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;
const int maxn=100000+10;
const int maxm=100000+10;
struct hh
{
  int v,next;
}e[maxm*2];
int n,m,point,l1,l2;
int head[maxn],used[maxn],ans1[maxn],ans2[maxn],dep[maxn];
template <class T> void read(T&x)
{
  x=0;char c=getchar();int f=0;
  while(c<'0'||c>'9'){f|=(c=='-');c=getchar();}
  while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();
  x=f?-x:x;
}
void add(int u,int v)
{
  e[++point].v=v;e[point].next=head[u];head[u]=point;
  e[++point].v=u;e[point].next=head[v];head[v]=point;
}
bool cmp(int a,int b){return a>b;}
void dfs(int x,int col,int de)
{
  used[x]=col;dep[x]=de;
  for(int i=head[x];~i;i=e[i].next)
  {
    int v=e[i].v;
    if(used[v]&&used[v]==used[i]&&dep[v]<x)
    {
      puts("-1");
      exit(0);
    }
    if(!dep[v])dfs(v,col==1?2:1,de+1);
  }
  return;
}
int main()
{
  memset(head,-1,sizeof(head));
  read(n);read(m);
  for(int i=1;i<=m;i++)
  {
    int u,v;
    read(u);read(v);
    add(u,v);
  }
  for(int i=1;i<=n;i++)if(!used[i])dfs(i,1,1);
  for(int i=1;i<=n;i++)used[i]==1?ans1[++l1]=i:ans2[++l2]=i;
  printf("%d\n",l1);
  for(int i=1;i<=l1;i++)printf("%d ",ans1[i]);
  printf("\n");
  printf("%d\n",l2);
  for(int i=1;i<=l2;i++)printf("%d ",ans2[i]);
  return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>

#define pb push_back
#define ll long long
#define REP(a,b) for(int(a)=0;(a)<(b); (a)++)
using namespace std;

vector<int> hr[100011];
int vysl[100011];

bool spust(int akt){
//	if(hr[akt].size() == 0) vysl[akt] = 0;
	REP(a,hr[akt].size()){
		int dal = hr[akt][a];
		if(vysl[akt] == vysl[dal]) return false;
		if(vysl[dal] == 0){
			if(vysl[akt] == 1)
				vysl[dal] = 2;
			else
				vysl[dal] = 1;
			spust(dal);
		}
	}
	return true;
}

int main(){
	int n,m;
	scanf("%i%i",&n,&m);
	REP(a,m){
		int o,d;
		scanf("%i%i",&o,&d);
		o--;d--;
		hr[o].pb(d);
		hr[d].pb(o);
	}

	REP(a,n){
		if(vysl[a] == 0){
			vysl[a] = 1;
			if(!spust(a)){
				printf("-1\n");
				return 0;
			}
		}
	}
	vector<int> jj;
	vector<int> dd;
	REP(a,n){
		if(vysl[a] == 1) {
			jj.pb(a);
		}
		if(vysl[a] == 2){
			dd.pb(a);
		}
	}

	printf("%lu\n",dd.size());
	REP(a,dd.size()){
		if(a == dd.size()-1) printf("%i\n",dd[a]+1);
		else printf("%i ",dd[a]+1);
	}
	printf("%lu\n",jj.size());
	REP(a,jj.size()){
		if(a == jj.size()-1) printf("%i\n",jj[a]+1);
		else printf("%i ",jj[a]+1);
	}

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>

#define pb push_back
#define ll long long
#define REP(a,b) for(int(a)=0;(a)<(b); (a)++)
using namespace std;

vector<int> hr[100011];
int vysl[100011];

bool spust(int akt){
//	if(hr[akt].size() == 0) vysl[akt] = 0;
	vector<int> hh;
	REP(a,hr[akt].size()){
		int dal = hr[akt][a];
		if(vysl[akt] == vysl[dal]) return false;
		if(vysl[dal] == 0){
			if(vysl[akt] == 1)
				vysl[dal] = 2;
			else
				vysl[dal] = 1;
			hh.pb(dal);
		}
	}
	REP(a,hh.size()){
		spust(hh[a]);
	}
	return true;
}

int main(){
	int n,m;
	scanf("%i%i",&n,&m);
	REP(a,m){
		int o,d;
		scanf("%i%i",&o,&d);
		o--;d--;
		hr[o].pb(d);
		hr[d].pb(o);
	}

	REP(a,n){
		if(vysl[a] == 0){
			vysl[a] = 1;
			if(!spust(a)){
				printf("-1\n");
				return 0;
			}
		}
	}
	vector<int> jj;
	vector<int> dd;
	REP(a,n){
		if(vysl[a] == 1) {
			jj.pb(a);
		}
		if(vysl[a] == 2){
			dd.pb(a);
		}
	}

	printf("%lu\n",dd.size());
	REP(a,dd.size()){
		if(a == dd.size()-1) printf("%i\n",dd[a]+1);
		else printf("%i ",dd[a]+1);
	}
	printf("%lu\n",jj.size());
	REP(a,jj.size()){
		if(a == jj.size()-1) printf("%i\n",jj[a]+1);
		else printf("%i ",jj[a]+1);
	}

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>

#define pb push_back
#define ll long long
#define REP(a,b) for(int(a)=0;(a)<(b); (a)++)
using namespace std;

vector<int> hr[100011];
int vysl[100011];

bool spust(int akt){
	if(hr[akt].size() == 0) vysl[akt] = 0;
	REP(a,hr[akt].size()){
		if(vysl[akt] == vysl[hr[akt][a]]) return false;
		if(0 == vysl[hr[akt][a]]){
			if(vysl[akt] == 1)
				vysl[hr[akt][a]] = 2;
			else
				vysl[hr[akt][a]] = 1;
			spust(hr[akt][a]);
		}
	}
	return true;
}

int main(){
	int n,m;
	scanf("%i%i",&n,&m);
	REP(a,m){
		int o,d;
		scanf("%i%i",&o,&d);
		o--;d--;
		hr[o].pb(d);
		hr[d].pb(o);
	}

	REP(a,n){
		if(vysl[a] == 0){
			vysl[a] = 1;
			if(!spust(a)){
				printf("-1\n");
				return 0;
			}
		}
	}
	int je = 0, dv = 0;
	vector<int> jj; vector<int> dd;
	REP(a,n){
		if(vysl[a] == 1) {
			je++;
			jj.pb(a);
		}
		if(vysl[a] == 2){
			dv++;
			dd.pb(a);
		}
	}

	printf("%i\n",dv);
	REP(a,dv)
		printf("%i ",dd[a]+1);
	printf("\n");
	printf("%i\n",je);
	REP(a,je)
		printf("%i ",jj[a]+1);
	printf("\n");

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>

#define pb push_back
#define ll long long
#define REP(a,b) for(int(a)=0;(a)<(b); (a)++)
using namespace std;

vector<int> hr[100011];
int vysl[100011];

bool spust(int akt){
//	if(hr[akt].size() == 0) vysl[akt] = 0;
	vector<int> hh;
	REP(a,hr[akt].size()){
		int dal = hr[akt][a];
		if(vysl[akt] == vysl[dal]) return false;
		if(vysl[dal] == 0){
			if(vysl[akt] == 1)
				vysl[dal] = 2;
			else
				vysl[dal] = 1;
			hh.pb(dal);
		}
	}
	REP(a,hh.size()){
		if(!spust(hh[a])) return false;
	}
	return true;
}

int main(){
	int n,m;
	scanf("%i%i",&n,&m);
	REP(a,m){
		int o,d;
		scanf("%i%i",&o,&d);
		o--;d--;
		hr[o].pb(d);
		hr[d].pb(o);
	}

	REP(a,n){
		if(vysl[a] == 0){
			vysl[a] = 1;
			if(!spust(a)){
				printf("-1\n");
				return 0;
			}
		}
	}
	vector<int> jj;
	vector<int> dd;
	REP(a,n){
		if(vysl[a] == 1) {
			jj.pb(a);
		}
		if(vysl[a] == 2){
			dd.pb(a);
		}
	}

	printf("%lu\n",dd.size());
	REP(a,dd.size()){
		if(a == dd.size()-1) printf("%i\n",dd[a]+1);
		else printf("%i ",dd[a]+1);
	}
	printf("%lu\n",jj.size());
	REP(a,jj.size()){
		if(a == jj.size()-1) printf("%i\n",jj[a]+1);
		else printf("%i ",jj[a]+1);
	}

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>

#define pb push_back
#define ll long long
#define REP(a,b) for(int(a)=0;(a)<(b); (a)++)
using namespace std;

vector<int> hr[100011];
int vysl[100011];

bool spust(int akt){
	REP(a,hr[akt].size()){
		if(vysl[akt] == vysl[hr[akt][a]]) return false;
		if(0 == vysl[hr[akt][a]]){
			if(vysl[akt] == 1)
				vysl[hr[akt][a]] = 2;
			else
				vysl[hr[akt][a]] = 1;
			spust(hr[akt][a]);
		}
	}
	return true;
}

int main(){
	int n,m;
	scanf("%i%i",&n,&m);
	REP(a,m){
		int o,d;
		scanf("%i%i",&o,&d);
		o--;d--;
		hr[o].pb(d);
		hr[d].pb(o);
	}

	REP(a,n){
		if(vysl[a] == 0){
			vysl[a] = 1;
			if(!spust(a)){
				printf("-1\n");
				return 0;
			}
		}
	}
	int je = 0, dv = 0;
	vector<int> jj; vector<int> dd;
	REP(a,n){
		if(vysl[a] == 1) {
			je++;
			jj.pb(a);
		}
		if(vysl[a] == 2){
			dv++;
			dd.pb(a);
		}
	}

	printf("%i\n",dv);
	REP(a,dv)
		printf("%i ",dd[a]+1);
	printf("\n");
	printf("%i\n",je);
	REP(a,je)
		printf("%i",jj[a]+1);
	printf("\n");

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>

#define pb push_back
#define ll long long
#define REP(a,b) for(int(a)=0;(a)<(b); (a)++)
using namespace std;

vector<int> hr[100011];
int vysl[1000011];

bool spust(int akt){
//	if(hr[akt].size() == 0) vysl[akt] = 0;
	REP(a,hr[akt].size()){
		int dal = hr[akt][a];
		if(vysl[akt] == vysl[dal]) return false;
		if(0 == vysl[dal]){
			if(vysl[akt] == 1)
				vysl[dal] = 2;
			else
				vysl[dal] = 1;
			spust(dal);
		}
	}
	return true;
}

int main(){
	int n,m;
	scanf("%i%i",&n,&m);
	REP(a,m){
		int o,d;
		scanf("%i%i",&o,&d);
		o--;d--;
		hr[o].pb(d);
		hr[d].pb(o);
	}

	REP(a,n){
		if(vysl[a] == 0){
			vysl[a] = 1;
			if(!spust(a)){
				printf("-1\n");
				return 0;
			}
		}
	}
	vector<int> jj;
	vector<int> dd;
	REP(a,n){
		if(vysl[a] == 1) {
			jj.pb(a);
		}
		if(vysl[a] == 2){
			dd.pb(a);
		}
	}

	printf("%lu\n",dd.size());
	REP(a,dd.size())
		printf("%i ",dd[a]+1);
	printf("\n");
	printf("%lu\n",jj.size());
	REP(a,jj.size())
		printf("%i ",jj[a]+1);
	printf("\n");

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>

#define pb push_back
#define ll long long
#define REP(a,b) for(int(a)=0;(a)<(b); (a)++)
using namespace std;

vector<int> hr[100011];
int vysl[100011];

bool spust(int akt){
//	if(hr[akt].size() == 0) vysl[akt] = 0;
	REP(a,hr[akt].size()){
		if(vysl[akt] == vysl[hr[akt][a]]) return false;
		if(0 == vysl[hr[akt][a]]){
			if(vysl[akt] == 1)
				vysl[hr[akt][a]] = 2;
			else
				vysl[hr[akt][a]] = 1;
			spust(hr[akt][a]);
		}
	}
	return true;
}

int main(){
	int n,m;
	scanf("%i%i",&n,&m);
	REP(a,m){
		int o,d;
		scanf("%i%i",&o,&d);
		o--;d--;
		hr[o].pb(d);
		hr[d].pb(o);
	}

	REP(a,n){
		if(vysl[a] == 0){
			vysl[a] = 1;
			if(!spust(a)){
				printf("-1\n");
				return 0;
			}
		}
	}
	vector<int> jj; vector<int> dd;
	REP(a,n){
		if(vysl[a] == 1) {
			jj.pb(a);
		}
		if(vysl[a] == 2){
			dd.pb(a);
		}
	}

	printf("%lu\n",dd.size());
	REP(a,dd.size())
		printf("%i ",dd[a]+1);
	printf("\n");
	printf("%lu\n",jj.size());
	REP(a,jj.size())
		printf("%i ",jj[a]+1);
	printf("\n");

	return 0;
}


#include <iostream>
#include <vector>

using namespace std;

vector < vector < int > > g;
vector < int > c;
vector < int > res1,res0;
bool sw;

void dfs(int nodo,int s){
    if( s == 0 ) res0.push_back(nodo);
    if(s == 1) res1.push_back(nodo);
    c[nodo] = s;
    for( int i = 0 ; i < g[nodo].size() ; i++ ){
        int nv = g[nodo][i];
        if( c[nv] == c[nodo] ){
            sw = false;
            return;
        }
        if(c[nodo] == -1 )dfs(nv,1-s);
    }
}

int main()
{
    int n, m, i, j;
    cin>>n>>m;
    g.assign(n,vector < int > (0) );
    c.assign(n,-1);
    while(m--){
        cin>>i>>j;
        g[i-1].push_back(j-1);
        g[j-1].push_back(i-1);
    }
    sw = true;
    m = 0;
    for(i = 0 ; i < c.size() ; i++){
        if(c[i]==-1 and g[i].size()!=0) dfs(i,0);
    }
    if(!sw ) cout<<-1;
    else{
        for( i = 0 ; i < c.size() ; i++ ){
            if( c[i] == -1 ) m ++;
        }
        cout<< m + res0.size()<<endl;
        for( i = 0 ; i < c.size() ; i++ ){
            if( c[i] == -1 ) cout<<i + 1<<' ';
        }
        for( i = 0 ; i < res0.size() ; i++ ){
            cout<<res0[i] + 1<<' ';
        }
        cout<<endl<<res1.size()<<endl;
        for( i = 0 ; i < res1.size() ; i++ ){
            cout<<res1[i] + 1<<' ';
        }
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <stdio.h>

using namespace std;

vector < vector < int > > g;
vector < int > c, v1, v0;
bool sw;

void dfs( int nodo, int col ){
    c[nodo] = col;
    if( col == 0 ) v0.push_back( nodo );
    else v1.push_back( nodo );
    for( int i = 0 ; i < g[nodo].size() ; i++ ){
        int nv = g[nodo][i];
        if( c[nv] == -1 ) dfs( nv, 1 - col );
        else if( c[nv] == col ) sw = false;
    }
}

int main()
{
    int i, n, m, j;
    scanf( "%d %d", &n, &m );
    g.assign( n, vector < int > (0) );
    v1.clear();
    v0.clear();
    c.assign( n, -1 );
    while( m-- ){
        scanf( "%d %d" , &i , &j );
        i--;
        j--;
        g[i].push_back(j);
        g[j].push_back(i);
    }
    sw = true;
    for( i = 0 ; i < g.size() ; i++ ){
        if( c[i] == -1 ) dfs( i , 0 );
    }
    if(!sw) printf("-1\n");
    else{
        printf("%d\n", v0.size());
        for( i = 0 ; i < v0.size() ; i++ ){
            printf( "%d ", v0[i] + 1 );
        }
        printf("\n");
        printf("%d\n", v1.size());
        for( i = 0 ; i < v1.size() ; i++ ){
            printf( "%d ", v1[i] + 1 );
        }
    }
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

vector < vector < int > > g;
vector < int > c;
vector < int > res1,res0;
bool sw;

void dfs(int nodo,int s){
    if(c[nodo]!=-1) return;
    if( s == 0 ) res0.push_back(nodo);
    else res1.push_back(nodo);
    c[nodo] = s;
    for( int i = 0 ; i < g[nodo].size() ; i++ ){
        int nv = g[nodo][i];
        if( c[nv] == c[nodo] ){
            sw = false;
            return;
        }
        dfs(nv, 1 - s );
    }
}

int main()
{
    int n, m, i, j;
    cin>>n>>m;
    g.assign(n,vector < int > (0) );
    c.assign(n,-1);
    while(m--){
        cin>>i>>j;
        g[i-1].push_back(j-1);
        g[j-1].push_back(i-1);
    }
    sw = true;
    dfs(j-1,0);
    m = 0;
    if(!sw) cout<<-1;
    else{
        for( i = 0 ; i < c.size() ; i++ ){
            if( c[i] == -1 ) m ++;
        }
        cout<< m + res0.size()<<endl;
        for( i = 0 ; i < c.size() ; i++ ){
            if( c[i] == -1 ) cout<<i + 1<<' ';
        }
        for( i = 0 ; i < res0.size() ; i++ ){
            cout<<res0[i] + 1<<' ';
        }
        cout<<endl<<res1.size()<<endl;
        for( i = 0 ; i < res1.size() ; i++ ){
            cout<<res1[i] + 1<<' ';
        }
    }
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

vector < vector < int > > g;
vector < int > c;
vector < int > res1,res0;
bool sw;

void dfs(int nodo,int s){
    if(c[nodo]!=-1) return;
    if( s == 0 ) res0.push_back(nodo);
    else res1.push_back(nodo);
    c[nodo] = s;
    for( int i = 0 ; i < g[nodo].size() ; i++ ){
        int nv = g[nodo][i];
        if( c[nv] == c[nodo] ){
            sw = false;
            return;
        }
        dfs(nv, 1 - s );
    }
}

int main()
{
    int n, m, i, j;
    cin>>n>>m;
    g.assign(n,vector < int > (0) );
    c.assign(n,-1);
    while(m--){
        cin>>i>>j;
        g[i-1].push_back(j-1);
        g[j-1].push_back(i-1);
    }
    sw = true;
    dfs(0,0);
    m = 0;
    if(!sw) cout<<-1;
    else{
        for( i = 0 ; i < c.size() ; i++ ){
            if( c[i] == -1 ) m ++;
        }
        cout<< m + res0.size()<<endl;
        for( i = 0 ; i < c.size() ; i++ ){
            if( c[i] == -1 ) cout<<i + 1<<' ';
        }
        for( i = 0 ; i < res0.size() ; i++ ){
            cout<<res0[i] + 1<<' ';
        }
        cout<<endl<<res1.size()<<endl;
        for( i = 0 ; i < res1.size() ; i++ ){
            cout<<res1[i] + 1<<' ';
        }
    }
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

vector < vector < int > > g;
vector < int > c;
vector < int > res1,res0;
bool sw;

void dfs(int nodo,int s){
    if(c[nodo]!=-1) return;
    if( s == 0 ) res0.push_back(nodo);
    else res1.push_back(nodo);
    c[nodo] = s;
    for( int i = 0 ; i < g[nodo].size() ; i++ ){
        int nv = g[nodo][i];
        if( c[nv] == c[nodo] ){
            sw = false;
            return;
        }
        dfs(nv, 1 - s );
    }
}

int main()
{
    int n, m, i, j;
    cin>>n>>m;
    g.assign(n,vector < int > (0) );
    c.assign(n,-1);
    while(m--){
        cin>>i>>j;
        g[i-1].push_back(j-1);
        g[j-1].push_back(i-1);
    }
    sw = true;
    dfs(i-1,0);
    m = 0;
    if(!sw) cout<<-1;
    else{
        /*
        for( i = 0 ; i < c.size() ; i++ ){
            if( c[i] == -1 ) m ++;
        }
        cout<< m + res0.size()<<endl;
        for( i = 0 ; i < c.size() ; i++ ){
            if( c[i] == -1 ) cout<<i + 1<<' ';
        }*/
        cout<<res0.size()<<endl;
        for( i = 0 ; i < res0.size() ; i++ ){
            cout<<res0[i] + 1<<' ';
        }
        cout<<endl<<res1.size()<<endl;
        for( i = 0 ; i < res1.size() ; i++ ){
            cout<<res1[i] + 1<<' ';
        }
    }
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

vector < vector < int > > g;
vector < int > c;
vector < int > res1,res0;
bool sw;

void dfs(int nodo,int s){
    if(c[nodo]!=-1) return;
    if( s == 0 ) res0.push_back(nodo);
    else res1.push_back(nodo);
    c[nodo] = s;
    for( int i = 0 ; i < g[nodo].size() ; i++ ){
        int nv = g[nodo][i];
        if( c[nv] == c[nodo] ){
            sw = false;
            return;
        }
        dfs(nv, 1 - s );
    }
}

int main()
{
    int n, m, i, j;
    cin>>n>>m;
    g.assign(n,vector < int > (0) );
    c.assign(n,-1);
    while(m--){
        cin>>i>>j;
        g[i-1].push_back(j-1);
        g[j-1].push_back(i-1);
    }
    sw = true;
    dfs(i-1,0);
    m = 0;
    if(!sw) cout<<-1;
    else{
        for( i = 0 ; i < c.size() ; i++ ){
            if( c[i] == -1 ) m ++;
        }
        cout<< m + res0.size()<<endl;
        for( i = 0 ; i < c.size() ; i++ ){
            if( c[i] == -1 ) cout<<i + 1<<' ';
        }
        for( i = 0 ; i < res0.size() ; i++ ){
            cout<<res0[i] + 1<<' ';
        }
        cout<<endl<<res1.size()<<endl;
        for( i = 0 ; i < res1.size() ; i++ ){
            cout<<res1[i] + 1<<' ';
        }
    }
    return 0;
}


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

#define ll long long
#define ld long double
#define pb push_back
#define ins insert
#define in push
#define out pop
#define loop(i,n) for(i=1;i<=n;i++)
#define loon(i,n) for(i=n;i>0;i--)
#define vctr(x) vector< x >
#define pii(x,y) pair< x,y >
#define mkpr(x,y) make_pair(x,y)
#define ft first
#define sd second
#define MX 1000005
#define mod 1000000007
#define INF 10000000000000

ll prt[MX],dis[MX],edg[MX];
vector<ll>ed[MX],con_comp,A,B;
bool visited[MX];
ll color[MX];

bool DFS(ll nd, ll CArea)
{
    visited[nd]=true;
    if(CArea==1)
        A.pb(nd);
    else
        B.pb(nd);
    color[nd]=CArea;

    ll n=edg[nd];
    for(ll i=0;i<n;i++){
            if(visited[ed[nd][i]] && color[ed[nd][i]]!=3-CArea)
                return false;

            if(!visited[ed[nd][i]]){
                if(!DFS(ed[nd][i],3-CArea))
                    return false;
            }

    }
    return true;
}

int main()
{
    ll n,m,a,b,c,t,i,j,k;
    string s;

    cin>> n >> m;

    loop(i,m){
        cin>> a >> b;

        ed[a].pb(b);
        ed[b].pb(a);
        edg[a]++;
        edg[b]++;
    }

    for(i=1;i<=n;i++){
        if(visited[i])
            continue;

        if(!edg[i])
            continue;

        if(!DFS(i,1)){
            cout<< -1;
            return 0;
        }
    }

    if(!A.size() || !B.size()){
        cout<< -1;
        return 0;
    }

    //sort(A.begin(),A.end());
    //sort(B.begin(),B.end());

    cout<< A.size() << endl;
    n=A.size();
    for(i=0;i<n;i++)
        cout<< A[i] << ' ';
    cout<< endl;

    cout<< B.size() << endl;
    n=B.size();
    for(i=0;i<n;i++)
        cout<< B[i] << ' ';
    cout<< endl;

    return 0;
}


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

#define ll long long
#define ld long double
#define pb push_back
#define ins insert
#define in push
#define out pop
#define loop(i,n) for(i=1;i<=n;i++)
#define loon(i,n) for(i=n;i>0;i--)
#define vctr(x) vector< x >
#define pii(x,y) pair< x,y >
#define mkpr(x,y) make_pair(x,y)
#define ft first
#define sd second
#define MX 100005
#define mod 1000000007
#define INF 10000000000000

ll prt[MX],dis[MX],edg[MX];
vector<ll>ed[MX],con_comp,A,B;
bool visited[MX];
map<ll,bool>mpA,mpB;

bool DFS(ll nd, ll CArea)
{
    if(visited[nd])
        return true;
    visited[nd]=true;
    if(CArea==1)
        mpA[nd]=true,A.pb(nd);
    else
        mpB[nd]=true,B.pb(nd);

    ll n=edg[nd];
    for(ll i=0;i<n;i++){
        if(CArea==1){
            if(visited[ed[nd][i]] && mpA[ed[nd][i]])
                return false;
            bool ok=DFS(ed[nd][i],2);
            if(!ok)
                return false;
        }
        else{
            if(visited[ed[nd][i]] && mpB[ed[nd][i]])
                return false;
            bool ok=DFS(ed[nd][i],1);
            if(!ok)
                return false;
        }

    }
    return true;
}

int main()
{
    ll n,m,a,b,c,t,i,j,k;
    string s;

    cin>> n >> m;

    loop(i,m){
        cin>> a >> b;

        ed[a].pb(b);
        ed[b].pb(a);
        edg[a]++;
        edg[b]++;
    }

    for(i=1;i<=n;i++){
        if(visited[i])
            continue;

        if(!edg[i])
            continue;

        A.clear();B.clear();
        if(DFS(i,1) && A.size() && B.size())
            break;
    }

    if(i>n){
        cout<< -1;
        return 0;
    }

    sort(A.begin(),A.end());
    sort(B.begin(),B.end());

    cout<< A.size() << endl;
    n=A.size();
    for(i=0;i<n;i++)
        cout<< A[i] << ' ';
    cout<< endl;

    cout<< B.size() << endl;
    n=B.size();
    for(i=0;i<n;i++)
        cout<< B[i] << ' ';
    cout<< endl;

    return 0;
}


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

#define ll long long
#define ld long double
#define pb push_back
#define ins insert
#define in push
#define out pop
#define loop(i,n) for(i=1;i<=n;i++)
#define loon(i,n) for(i=n;i>0;i--)
#define vctr(x) vector< x >
#define pii(x,y) pair< x,y >
#define mkpr(x,y) make_pair(x,y)
#define ft first
#define sd second
#define MX 100005
#define mod 1000000007
#define INF 10000000000000

ll prt[MX],dis[MX],edg[MX];
vector<ll>ed[MX],con_comp,A,B;
bool visited[MX];

void DDFS(ll s)
{
    bool vis[MX];
    memset(vis, false, sizeof vis);
    A.clear();
    B.clear();

    map<ll,bool>mpA,mpB;
    stack<ll>Q;
    Q.in(s);
    vis[s]=true;
    A.pb(s);
    mpA[s]=true;

    while(!Q.empty()){
        ll u=Q.top();
        Q.out();

        ll n=ed[u].size(),i;
        loop(i,n){
            if(vis[ed[u][i-1]])
                continue;

            ll v=ed[u][i-1];
            if(mpA[u])
                mpB[v]=true,B.pb(v);
            else if(mpB[u])
                mpA[v]=true,A.pb(v);
            vis[ed[u][i-1]]=true;
            Q.in(ed[u][i-1]);
        }
    }

    ll m=A.size();
    for(ll i=0;i<m;i++){
        ll n=edg[A[i]];
        for(ll j=0;j<n;j++)
            if(mpA[ed[A[i]][j]])
                A.clear();
    }

    m=B.size();
    for(ll i=0;i<m;i++){
        ll n=edg[B[i]];
        for(ll j=0;j<n;j++)
            if(mpB[ed[B[i]][j]])
                B.clear();
    }

}

void DFS(ll nd)
{
    if(visited[nd])
        return;
    visited[nd]=true;
    con_comp.pb(nd);

    ll n=edg[nd];
    for(ll i=0;i<n;i++)
        DFS(ed[nd][i]);

    return;
}

int main()
{
    ll n,m,a,b,c,t,i,j,k;
    string s;

    cin>> n >> m;

    loop(i,m){
        cin>> a >> b;

        ed[a].pb(b);
        ed[b].pb(a);
        edg[a]++;
        edg[b]++;
    }

    for(i=1;i<=n;i++){
        if(visited[i])
            continue;
        con_comp.clear();
        DFS(i);
        m=con_comp.size();
        ll edge=0;
        for(j=0;j<m;j++)
            edge+=edg[con_comp[j]];
        edge/=2;

        /*for(j=0;j<m;j++)
            cerr<< con_comp[j] << ' ';
        cerr<< endl;*/

        if(/*edge!=m-1 || */!edge)
            continue;

        DDFS(con_comp[0]);
        if(A.size() && B.size())
            break;
    }

    if(i>n){
        cout<< -1;
        return 0;
    }

    sort(A.begin(),A.end());
    sort(B.begin(),B.end());

    cout<< A.size() << endl;
    n=A.size();
    for(i=0;i<n;i++)
        cout<< A[i] << ' ';
    cout<< endl;

    cout<< B.size() << endl;
    n=B.size();
    for(i=0;i<n;i++)
        cout<< B[i] << ' ';
    cout<< endl;

    return 0;
}


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

#define ll long long
#define ld long double
#define pb push_back
#define ins insert
#define in push
#define out pop
#define loop(i,n) for(i=1;i<=n;i++)
#define loon(i,n) for(i=n;i>0;i--)
#define vctr(x) vector< x >
#define pii(x,y) pair< x,y >
#define mkpr(x,y) make_pair(x,y)
#define ft first
#define sd second
#define MX 100005
#define mod 1000000007
#define INF 10000000000000

ll prt[MX],dis[MX],edg[MX];
vector<ll>ed[MX],con_comp,A,B;
bool visited[MX];

void DDFS(ll s)
{
    bool vis[MX];
    memset(vis, false, sizeof vis);
    A.clear();
    B.clear();

    map<ll,bool>mpA,mpB;
    stack<ll>Q;
    Q.in(s);
    vis[s]=true;
    A.pb(s);
    mpA[s]=true;

    while(!Q.empty()){
        ll u=Q.top();
        Q.out();

        ll n=ed[u].size(),i;
        loop(i,n){
            if(vis[ed[u][i-1]])
                continue;

            ll v=ed[u][i-1];
            if(mpA[u])
                mpB[v]=true,B.pb(v);
            else if(mpB[u])
                mpA[v]=true,A.pb(v);
            vis[ed[u][i-1]]=true;
            Q.in(ed[u][i-1]);
        }
    }

    ll m=A.size();
    for(ll i=0;i<m;i++){
        ll n=edg[A[i]];
        for(ll j=0;j<n;j++)
            if(mpA[ed[A[i]][j]])
                A.clear();
    }

    m=B.size();
    for(ll i=0;i<m;i++){
        ll n=edg[B[i]];
        for(ll j=0;j<n;j++)
            if(mpA[ed[B[i]][j]])
                B.clear();
    }

}

void DFS(ll nd)
{
    if(visited[nd])
        return;
    visited[nd]=true;
    con_comp.pb(nd);

    ll n=edg[nd];
    for(ll i=0;i<n;i++)
        DFS(ed[nd][i]);

    return;
}

int main()
{
    ll n,m,a,b,c,t,i,j,k;
    string s;

    cin>> n >> m;

    loop(i,m){
        cin>> a >> b;

        ed[a].pb(b);
        ed[b].pb(a);
        edg[a]++;
        edg[b]++;
    }

    for(i=1;i<=n;i++){
        if(visited[i])
            continue;
        con_comp.clear();
        DFS(i);
        m=con_comp.size();
        ll edge=0;
        for(j=0;j<m;j++)
            edge+=edg[con_comp[j]];
        edge/=2;

        /*for(j=0;j<m;j++)
            cerr<< con_comp[j] << ' ';
        cerr<< endl;*/

        if(/*edge!=m-1 || */!edge)
            continue;

        DDFS(con_comp[0]);
        if(A.size() && B.size())
            break;
    }

    if(i>n){
        cout<< -1;
        return 0;
    }

    sort(A.begin(),A.end());
    sort(B.begin(),B.end());

    cout<< A.size() << endl;
    n=A.size();
    for(i=0;i<n;i++)
        cout<< A[i] << ' ';
    cout<< endl;

    cout<< B.size() << endl;
    n=B.size();
    for(i=0;i<n;i++)
        cout<< B[i] << ' ';
    cout<< endl;

    return 0;
}


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

#define ll long long
#define ld long double
#define pb push_back
#define ins insert
#define in push
#define out pop
#define loop(i,n) for(i=1;i<=n;i++)
#define loon(i,n) for(i=n;i>0;i--)
#define vctr(x) vector< x >
#define pii(x,y) pair< x,y >
#define mkpr(x,y) make_pair(x,y)
#define ft first
#define sd second
#define MX 100005
#define mod 1000000007
#define INF 10000000000000

ll prt[MX],dis[MX],edg[MX];
vector<ll>ed[MX],con_comp,A,B;
bool visited[MX];
ll color[MX];

bool DFS(ll nd, ll CArea)
{
    visited[nd]=true;
    if(CArea==1)
        A.pb(nd);
    else
        B.pb(nd);

    ll n=edg[nd];
    for(ll i=0;i<n;i++){
            if(visited[ed[nd][i]] && color[ed[nd][i]]!=3-CArea)
                return false;

            if(!visited[ed[nd][i]]){
                color[ed[nd][i]]=3-CArea;
                if(!DFS(ed[nd][i],3-CArea))
                    return false;
            }

    }
    return true;
}

int main()
{
    ll n,m,a,b,c,t,i,j,k;
    string s;

    cin>> n >> m;

    loop(i,m){
        cin>> a >> b;

        ed[a].pb(b);
        ed[b].pb(a);
        edg[a]++;
        edg[b]++;
    }

    for(i=1;i<=n;i++){
        if(visited[i])
            continue;

        if(!edg[i])
            continue;

        color[i]=1;
        A.clear();B.clear();
        if(DFS(i,1) && A.size() && B.size())
            break;
        cout<< -1;
        return 0;
    }

    if(i>n){
        cout<< -1;
        return 0;
    }

    sort(A.begin(),A.end());
    sort(B.begin(),B.end());

    cout<< A.size() << endl;
    n=A.size();
    for(i=0;i<n;i++)
        cout<< A[i] << ' ';
    cout<< endl;

    cout<< B.size() << endl;
    n=B.size();
    for(i=0;i<n;i++)
        cout<< B[i] << ' ';
    cout<< endl;

    return 0;
}


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

#define ll long long
#define ld long double
#define pb push_back
#define ins insert
#define in push
#define out pop
#define loop(i,n) for(i=1;i<=n;i++)
#define loon(i,n) for(i=n;i>0;i--)
#define vctr(x) vector< x >
#define pii(x,y) pair< x,y >
#define mkpr(x,y) make_pair(x,y)
#define ft first
#define sd second
#define MX 100005
#define mod 1000000007
#define INF 10000000000000

ll prt[MX],dis[MX],edg[MX];
vector<ll>ed[MX],con_comp,A,B;
bool visited[MX];
map<ll,bool>mpA,mpB;

bool DFS(ll nd, ll CArea)
{
    if(visited[nd]){
        if(CArea==1 && mpA[nd])
            return true;
        if(CArea==2 && mpB[nd])
            return true;
        return false;
    }

    visited[nd]=true;
    if(CArea==1)
        mpA[nd]=true,A.pb(nd);
    else
        mpB[nd]=true,B.pb(nd);

    ll n=edg[nd];
    for(ll i=0;i<n;i++){
        if(CArea==1)
            if(!DFS(ed[nd][i],2))
                return false;
        else
            if(!DFS(ed[nd][i],1))
                return false;
    }
    return true;
}

int main()
{
    ll n,m,a,b,c,t,i,j,k;
    string s;

    cin>> n >> m;

    loop(i,m){
        cin>> a >> b;

        ed[a].pb(b);
        ed[b].pb(a);
        edg[a]++;
        edg[b]++;
    }

    for(i=1;i<=n;i++){
        if(visited[i])
            continue;

        if(!edg[i])
            continue;

        A.clear();B.clear();
        if(DFS(i,1))
            break;
    }

    if(i>n){
        cout<< -1;
        return 0;
    }

    sort(A.begin(),A.end());
    sort(B.begin(),B.end());

    cout<< A.size() << endl;
    n=A.size();
    for(i=0;i<n;i++)
        cout<< A[i] << ' ';
    cout<< endl;

    cout<< B.size() << endl;
    n=B.size();
    for(i=0;i<n;i++)
        cout<< B[i] << ' ';
    cout<< endl;

    return 0;
}


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

#define ll long long
#define ld long double
#define pb push_back
#define ins insert
#define in push
#define out pop
#define loop(i,n) for(i=1;i<=n;i++)
#define loon(i,n) for(i=n;i>0;i--)
#define vctr(x) vector< x >
#define pii(x,y) pair< x,y >
#define mkpr(x,y) make_pair(x,y)
#define ft first
#define sd second
#define MX 1000005
#define mod 1000000007
#define INF 10000000000000

ll prt[MX],dis[MX],edg[MX];
vector<ll>ed[MX],con_comp,A,B;
bool visited[MX];
ll color[MX];

bool DFS(ll nd, ll CArea)
{
    visited[nd]=true;
    if(CArea==1)
        A.pb(nd);
    else
        B.pb(nd);
    color[nd]=CArea;

    ll n=edg[nd];
    for(ll i=0;i<n;i++){
            if(visited[ed[nd][i]] && color[ed[nd][i]]!=3-CArea)
                return false;

            if(!visited[ed[nd][i]]){
                if(!DFS(ed[nd][i],3-CArea))
                    return false;
            }

    }
    return true;
}

int main()
{
    ll n,m,a,b,c,t,i,j,k;
    string s;

    cin>> n >> m;

    loop(i,m){
        cin>> a >> b;

        ed[a].pb(b);
        ed[b].pb(a);
        edg[a]++;
        edg[b]++;
    }

    for(i=1;i<=n;i++){
        if(visited[i])
            continue;

        if(!edg[i])
            continue;

        if(!DFS(i,1)){
            cout<< -1;
            return 0;
        }
    }

    if(i>n || !A.size() || !B.size()){
        cout<< -1;
        return 0;
    }

    //sort(A.begin(),A.end());
    //sort(B.begin(),B.end());

    cout<< A.size() << endl;
    n=A.size();
    for(i=0;i<n;i++)
        cout<< A[i] << ' ';
    cout<< endl;

    cout<< B.size() << endl;
    n=B.size();
    for(i=0;i<n;i++)
        cout<< B[i] << ' ';
    cout<< endl;

    return 0;
}


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

#define ll long long
#define ld long double
#define pb push_back
#define ins insert
#define in push
#define out pop
#define loop(i,n) for(i=1;i<=n;i++)
#define loon(i,n) for(i=n;i>0;i--)
#define vctr(x) vector< x >
#define pii(x,y) pair< x,y >
#define mkpr(x,y) make_pair(x,y)
#define ft first
#define sd second
#define MX 100005
#define mod 1000000007
#define INF 10000000000000

ll prt[MX],dis[MX],edg[MX];
vector<ll>ed[MX],con_comp,A,B;
bool visited[MX];
map<ll,bool>mpA,mpB;

bool DFS(ll nd, ll CArea)
{
    if(visited[nd])
        return true;
    visited[nd]=true;
    if(CArea==1)
        mpA[nd]=true,A.pb(nd);
    else
        mpB[nd]=true,B.pb(nd);

    ll n=edg[nd];
    for(ll i=0;i<n;i++){
        if(CArea==1){
            if(visited[ed[nd][i]] && mpA[ed[nd][i]])
                return false;
            bool ok=DFS(ed[nd][i],2);
            if(!ok)
                return false;
        }
        else{
            if(visited[ed[nd][i]] && mpB[ed[nd][i]])
                return false;
            bool ok=DFS(ed[nd][i],1);
            if(!ok)
                return false;
        }

    }
    return true;
}

int main()
{
    ll n,m,a,b,c,t,i,j,k;
    string s;

    cin>> n >> m;

    loop(i,m){
        cin>> a >> b;

        ed[a].pb(b);
        ed[b].pb(a);
        edg[a]++;
        edg[b]++;
    }

    for(i=1;i<=n;i++){
        if(visited[i])
            continue;

        if(!edg[i])
            continue;

        A.clear();B.clear();
        if(DFS(i,1))
            break;
    }

    if(i>n){
        cout<< -1;
        return 0;
    }

    sort(A.begin(),A.end());
    sort(B.begin(),B.end());

    cout<< A.size() << endl;
    n=A.size();
    for(i=0;i<n;i++)
        cout<< A[i] << ' ';
    cout<< endl;

    cout<< B.size() << endl;
    n=B.size();
    for(i=0;i<n;i++)
        cout<< B[i] << ' ';
    cout<< endl;

    return 0;
}


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

#define ll long long
#define ld long double
#define pb push_back
#define ins insert
#define in push
#define out pop
#define loop(i,n) for(i=1;i<=n;i++)
#define loon(i,n) for(i=n;i>0;i--)
#define vctr(x) vector< x >
#define pii(x,y) pair< x,y >
#define mkpr(x,y) make_pair(x,y)
#define ft first
#define sd second
#define MX 100005
#define mod 1000000007
#define INF 10000000000000

ll prt[MX],dis[MX],edg[MX];
vector<ll>ed[MX],con_comp,A,B;
bool visited[MX];

void DDFS(ll s)
{
    bool vis[MX];
    memset(vis, false, sizeof vis);

    map<ll,bool>mpA,mpB;
    stack<ll>Q;
    Q.in(s);
    vis[s]=true;
    A.pb(s);
    mpA[s]=true;

    while(!Q.empty()){
        ll u=Q.top();
        Q.out();

        ll n=ed[u].size(),i;
        loop(i,n){
            if(vis[ed[u][i-1]])
                continue;

            ll v=ed[u][i-1];
            if(mpA[u])
                mpB[v]=true,B.pb(v);
            else
                mpA[v]=true,A.pb(v);
            vis[ed[u][i-1]]=true;
            Q.in(ed[u][i-1]);

        }
    }

}

void DFS(ll nd)
{
    if(visited[nd])
        return;
    visited[nd]=true;
    con_comp.pb(nd);

    ll n=edg[nd];
    for(ll i=0;i<n;i++)
        DFS(ed[nd][i]);

    return;
}

int main()
{
    ll n,m,a,b,c,t,i,j,k;
    string s;

    cin>> n >> m;

    loop(i,m){
        cin>> a >> b;

        ed[a].pb(b);
        ed[b].pb(a);
        edg[a]++;
        edg[b]++;
    }

    for(i=1;i<=n;i++){
        if(visited[i])
            continue;
        con_comp.clear();
        DFS(i);
        m=con_comp.size();
        ll edge=0;
        for(j=0;j<m;j++)
            edge+=edg[con_comp[j]];
        edge/=2;

        if(edge!=m-1 || !edge)
            continue;

        DDFS(con_comp[0]);
        break;
    }

    if(i>n){
        cout<< -1;
        return 0;
    }

    sort(A.begin(),A.end());
    sort(B.begin(),B.end());

    cout<< A.size() << endl;
    n=A.size();
    for(i=0;i<n;i++)
        cout<< A[i] << ' ';
    cout<< endl;

    cout<< B.size() << endl;
    n=B.size();
    for(i=0;i<n;i++)
        cout<< B[i] << ' ';
    cout<< endl;

    return 0;
}


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

#define ll long long
#define ld long double
#define pb push_back
#define ins insert
#define in push
#define out pop
#define loop(i,n) for(i=1;i<=n;i++)
#define loon(i,n) for(i=n;i>0;i--)
#define vctr(x) vector< x >
#define pii(x,y) pair< x,y >
#define mkpr(x,y) make_pair(x,y)
#define ft first
#define sd second
#define MX 100005
#define mod 1000000007
#define INF 10000000000000

ll prt[MX],dis[MX],edg[MX];
vector<ll>ed[MX],con_comp,A,B;
bool visited[MX];
map<ll,bool>mpA,mpB;

bool DFS(ll nd, ll CArea)
{
    visited[nd]=true;
    if(CArea==1)
        mpA[nd]=true,A.pb(nd);
    else
        mpB[nd]=true,B.pb(nd);

    ll n=edg[nd];
    for(ll i=0;i<n;i++){
        if(CArea==1){
            if(visited[ed[nd][i]] && (mpA[ed[nd][i]] || !mpB[ed[nd][i]]))
                return false;

            if(!visited[ed[nd][i]]){
                if(!DFS(ed[nd][i],2))
                    return false;
            }
        }
        else{
            if(visited[ed[nd][i]] && (mpB[ed[nd][i]] || !mpA[ed[nd][i]]))
                return false;

            if(!visited[ed[nd][i]]){
                if(!DFS(ed[nd][i],1))
                    return false;
            }
        }

    }
    return true;
}

int main()
{
    ll n,m,a,b,c,t,i,j,k;
    string s;

    cin>> n >> m;

    loop(i,m){
        cin>> a >> b;

        ed[a].pb(b);
        ed[b].pb(a);
        edg[a]++;
        edg[b]++;
    }

    for(i=1;i<=n;i++){
        if(visited[i])
            continue;

        if(!edg[i])
            continue;

        A.clear();B.clear();
        if(DFS(i,1) && A.size() && B.size())
            break;
    }

    if(i>n){
        cout<< -1;
        return 0;
    }

    sort(A.begin(),A.end());
    sort(B.begin(),B.end());

    cout<< A.size() << endl;
    n=A.size();
    for(i=0;i<n;i++)
        cout<< A[i] << ' ';
    cout<< endl;

    cout<< B.size() << endl;
    n=B.size();
    for(i=0;i<n;i++)
        cout<< B[i] << ' ';
    cout<< endl;

    return 0;
}


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

#define ll long long
#define ld long double
#define pb push_back
#define ins insert
#define in push
#define out pop
#define loop(i,n) for(i=1;i<=n;i++)
#define loon(i,n) for(i=n;i>0;i--)
#define vctr(x) vector< x >
#define pii(x,y) pair< x,y >
#define mkpr(x,y) make_pair(x,y)
#define ft first
#define sd second
#define MX 100005
#define mod 1000000007
#define INF 10000000000000

ll prt[MX],dis[MX],edg[MX];
vector<ll>ed[MX],con_comp,A,B;
bool visited[MX];

bool DDFS(ll s)
{
    bool vis[MX];
    memset(vis, false, sizeof vis);
    A.clear();
    B.clear();

    map<ll,bool>mpA,mpB;
    stack<ll>Q;
    Q.in(s);
    vis[s]=true;
    A.pb(s);
    mpA[s]=true;

    while(!Q.empty()){
        ll u=Q.top();
        Q.out();

        ll n=ed[u].size(),i;
        loop(i,n){
            ll v=ed[u][i-1];
            if(vis[v] && mpA[u] && mpB[v])
                continue;
            else if(vis[v] && mpA[v] && mpB[u])
                continue;
            else if(vis[v])
                return false;

            if(mpA[u])
                mpB[v]=true,B.pb(v);
            else if(mpB[u])
                mpA[v]=true,A.pb(v);
            vis[v]=true;
            Q.in(v);
        }
    }

    return true;

}

int main()
{
    ll n,m,a,b,c,t,i,j,k;
    string s;

    cin>> n >> m;

    loop(i,m){
        cin>> a >> b;

        ed[a].pb(b);
        ed[b].pb(a);
        edg[a]++;
        edg[b]++;
    }

    for(i=1;i<=n;i++){
        if(visited[i])
            continue;

        if(!edg[i])
            continue;

        if(DDFS(i))
            break;
    }

    if(i>n){
        cout<< -1;
        return 0;
    }

    sort(A.begin(),A.end());
    sort(B.begin(),B.end());

    cout<< A.size() << endl;
    n=A.size();
    for(i=0;i<n;i++)
        cout<< A[i] << ' ';
    cout<< endl;

    cout<< B.size() << endl;
    n=B.size();
    for(i=0;i<n;i++)
        cout<< B[i] << ' ';
    cout<< endl;

    return 0;
}


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

#define ll long long
#define ld long double
#define pb push_back
#define ins insert
#define in push
#define out pop
#define loop(i,n) for(i=1;i<=n;i++)
#define loon(i,n) for(i=n;i>0;i--)
#define vctr(x) vector< x >
#define pii(x,y) pair< x,y >
#define mkpr(x,y) make_pair(x,y)
#define ft first
#define sd second
#define MX 1000005
#define mod 1000000007
#define INF 10000000000000

ll prt[MX],dis[MX],edg[MX];
vector<ll>ed[MX],con_comp,A,B;
bool visited[MX];
ll color[MX];

bool DFS(ll nd, ll CArea)
{
    visited[nd]=true;
    if(CArea==1)
        A.pb(nd);
    else
        B.pb(nd);
    color[nd]=CArea;

    ll n=edg[nd];
    for(ll i=0;i<n;i++){
            if(visited[ed[nd][i]] && color[ed[nd][i]]!=3-CArea)
                return false;

            if(!visited[ed[nd][i]]){
                if(!DFS(ed[nd][i],3-CArea))
                    return false;
            }

    }
    return true;
}

int main()
{
    ll n,m,a,b,c,t,i,j,k;
    string s;

    cin>> n >> m;

    loop(i,m){
        cin>> a >> b;

        ed[a].pb(b);
        ed[b].pb(a);
        edg[a]++;
        edg[b]++;
    }

    for(i=1;i<=n;i++){
        if(visited[i])
            continue;

        if(!edg[i])
            continue;

        A.clear();B.clear();
        if(DFS(i,1) && A.size() && B.size())
            break;
        cout<< -1;
        return 0;
    }

    if(i>n){
        cout<< -1;
        return 0;
    }

    //sort(A.begin(),A.end());
    //sort(B.begin(),B.end());

    cout<< A.size() << endl;
    n=A.size();
    for(i=0;i<n;i++)
        cout<< A[i] << ' ';
    cout<< endl;

    cout<< B.size() << endl;
    n=B.size();
    for(i=0;i<n;i++)
        cout<< B[i] << ' ';
    cout<< endl;

    return 0;
}


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

#define ll long long
#define ld long double
#define pb push_back
#define ins insert
#define in push
#define out pop
#define loop(i,n) for(i=1;i<=n;i++)
#define loon(i,n) for(i=n;i>0;i--)
#define vctr(x) vector< x >
#define pii(x,y) pair< x,y >
#define mkpr(x,y) make_pair(x,y)
#define ft first
#define sd second
#define MX 100005
#define mod 1000000007
#define INF 10000000000000

ll prt[MX],dis[MX],edg[MX];
vector<ll>ed[MX],con_comp,A,B;
bool visited[MX];
map<ll,bool>mpA,mpB;

bool DFS(ll nd, ll CArea)
{
    visited[nd]=true;
    if(CArea==1)
        mpA[nd]=true,A.pb(nd);
    else
        mpB[nd]=true,B.pb(nd);

    ll n=edg[nd];
    for(ll i=0;i<n;i++){
        if(CArea==1){
            if(visited[ed[nd][i]] && mpA[ed[nd][i]])
                return false;
            bool ok=DFS(ed[nd][i],2);
            if(!ok)
                return false;
        }
        else{
            if(visited[ed[nd][i]] && mpB[ed[nd][i]])
                return false;
            bool ok=DFS(ed[nd][i],1);
            if(!ok)
                return false;
        }

    }
    return true;
}

int main()
{
    ll n,m,a,b,c,t,i,j,k;
    string s;

    cin>> n >> m;

    loop(i,m){
        cin>> a >> b;

        ed[a].pb(b);
        ed[b].pb(a);
        edg[a]++;
        edg[b]++;
    }

    for(i=1;i<=n;i++){
        if(visited[i])
            continue;

        if(!edg[i])
            continue;

        A.clear();B.clear();
        if(DFS(i,1))
            break;
    }

    if(i>n){
        cout<< -1;
        return 0;
    }

    sort(A.begin(),A.end());
    sort(B.begin(),B.end());

    cout<< A.size() << endl;
    n=A.size();
    for(i=0;i<n;i++)
        cout<< A[i] << ' ';
    cout<< endl;

    cout<< B.size() << endl;
    n=B.size();
    for(i=0;i<n;i++)
        cout<< B[i] << ' ';
    cout<< endl;

    return 0;
}


#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <iomanip>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <sstream>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>

using namespace std;

struct bipart{
int color;
int index;
};

int main(){
    ios_base::sync_with_stdio(false);
    int n,m,u,v;
    cin>>n>>m;
    vector<vector<int> >graph(n);
    vector<int>a,b; //a(0),b(1)
    set<int>left;
    int visited[n],marked[n];
    memset(visited,0,sizeof(visited));
    for(int i=0; i<m; i++){
        cin>>u>>v;
        graph[u-1].push_back(v-1);
        graph[v-1].push_back(u-1);
        if(left.size()<n)
            left.insert(i);
    }
    if(m<n){
        for(int i=m; i<n; i++)
            left.insert(i);
    }
//    set<int>::iterator it=left.begin();
//    while(it!=left.end())
//    {
//        cout<<*it+1;
//        it++;
//    }
    bipart temp,top;
    stack<bipart>stek;
    while(!left.empty()){
        temp.color=0;
        temp.index=*left.begin();
        left.erase(left.begin());
        visited[temp.index]=1;
        marked[temp.index]=0;
        a.push_back(temp.index);
        stek.push(temp);
        while(!stek.empty()){
                top=stek.top();
                stek.pop();
                int node,index=top.index;
                for(int i=0; i<graph[index].size(); i++){
                        node=graph[index][i];
                        if(!visited[node]){
                            visited[node]=1;
                            temp.index=node;
                            temp.color=!top.color;
                            marked[node]=temp.color;
                            left.erase(node);
                            if(temp.color)
                                b.push_back(node);
                            else
                                a.push_back(node);
                            stek.push(temp);

                        }
                        else if(top.color==marked[node]){
                            cout<<"-1";
                            return 0;
                        }
                }
        }
    }
    cout<<a.size()<<endl;
    for(int i=0; i<a.size(); i++)
        cout<<a[i]+1<<" ";
    cout<<b.size()<<endl;
    for(int i=0; i<b.size(); i++)
        cout<<b[i]+1<<" ";

return 0;}


#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <iomanip>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <sstream>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>

using namespace std;

struct node{
int color;
int index;
};

int main(){
    int n,m,u,v;
    cin>>n>>m;
    int marked[n],visited[n];
    vector<vector<int> >graph(n);
    set<int>v1,v2;
    fill(visited,visited+n,0);
    for(int i=0; i<m; i++){
        cin>>u>>v;
        graph[u-1].push_back(v-1);
        graph[v-1].push_back(u-1);
    }

    stack<node>stek;
    node temp,top;
    temp.index=u-1;
    temp.color=0;
    visited[temp.index]=1;
    v2.insert(u-1);
    stek.push(temp);
    while(!stek.empty()){
        top=stek.top();
        stek.pop();
        for(int i=0; i<graph[top.index].size(); i++){
            v=graph[top.index][i];
            if(!visited[v]){
                visited[v]=1;
                temp.color=!top.color;
                temp.index=v;
                marked[v]=temp.color;
                stek.push(temp);
                if(temp.color)
                    v1.insert(v);
                else
                    v2.insert(v);
            }
            else if(top.color==marked[v]){
                cout<<"-1";
                return 0;
            }
        }
    }
    cout<<v1.size()<<endl;
    set<int>::iterator it;
    it=v1.begin();
    while(it!=v1.end()){
        cout<<*it+1<<" ";
        it++;
    }
    cout<<endl;
    cout<<v2.size()<<endl;
    it=v2.begin();
    while(it!=v2.end()){
        cout<<*it+1<<" ";
        it++;
    }

return 0;}


#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <iomanip>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <sstream>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <ctime>

using namespace std;

struct node{
int color;
int index;
};

int main(){
    int n,m,u,v;
    cin>>n>>m;
    int marked[n],visited[n];
    vector<vector<int> >graph(n);
    set<int>v1,v2,left;
    fill(visited,visited+n,0);
    for(int i=0; i<m; i++){
            left.insert(i);
        cin>>u>>v;
        graph[u-1].push_back(v-1);
        graph[v-1].push_back(u-1);
    }
    for(int i=m; i<n; i++)
        left.insert(i);
    stack<node>stek;
    node temp,top;
    while(!left.empty()){
     temp.index=*(left.begin());
    left.erase(left.begin());
    temp.color=0;
    visited[temp.index]=1;
    marked[temp.index]=0;
    v2.insert(temp.index);
    stek.push(temp);
    while(!stek.empty()){
        top=stek.top();
        stek.pop();
        for(int i=0; i<graph[top.index].size(); i++){
            v=graph[top.index][i];
            if(!visited[v]){
                visited[v]=1;
                temp.color=!top.color;
                temp.index=v;
                marked[v]=temp.color;
                left.erase(v);
                stek.push(temp);
                if(temp.color)
                    v1.insert(v);
                else
                    v2.insert(v);
            }
            else if(top.color==marked[v]){
                cout<<"-1";
                return 0;
            }
        }
    }
        }
    cout<<v1.size()<<endl;
    set<int>::iterator it;
    it=v1.begin();
    while(it!=v1.end()){
        cout<<*it+1<<" ";
        it++;
    }
    cout<<endl;
    cout<<v2.size()<<endl;
    it=v2.begin();
    while(it!=v2.end()){
        cout<<*it+1<<" ";
        it++;
    }

return 0;}


#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <iomanip>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <sstream>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>

using namespace std;

struct node{
int color;
int index;
};

int main(){
    int n,m,u,v;
    cin>>n>>m;
    int marked[n],visited[n];
    vector<vector<int> >graph(n);
    set<int>v1,v2;
    fill(marked,marked+n,0);
    fill(visited,visited+n,0);
    for(int i=0; i<m; i++){
        cin>>u>>v;
        graph[u-1].push_back(v-1);
        graph[v-1].push_back(u-1);
    }
    stack<node>stek;
    node top,temp;
    temp.color=0;
    temp.index=u-1;
    visited[temp.index]=1;
    v2.insert(temp.index);
    stek.push(temp);
    while(!stek.empty()){
        top=stek.top();
        stek.pop();
        for(int i=0; i<graph[top.index].size(); i++){
            v=graph[top.index][i];
            if(!visited[v]){
                    visited[v]=1;
                    temp.color=!top.color;
                    marked[v]=temp.color;
                    temp.index=v;
                    stek.push(temp);
                    if(temp.color)
                        v1.insert(v);
                    else
                        v2.insert(v);

            }
            else if(visited[v] && temp.color==marked[v]){
                    cout<<"-1";
            return 0;

            }
        }
    }
    cout<<v1.size()<<endl;
    set<int>::iterator it;
    it=v1.begin();
    while(it!=v1.end()){
        cout<<*it+1<<" ";
        it++;
    }
    cout<<endl;
    cout<<v2.size()<<endl;
    it=v2.begin();
    while(it!=v2.end()){
        cout<<*it+1<<" ";
        it++;
    }

return 0;}


#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <iomanip>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <sstream>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <ctime>

using namespace std;

struct node{
int color;
int index;
};

int main(){
    int n,m,u,v;
    cin>>n>>m;
    int marked[n],visited[n];
    vector<vector<int> >graph(n);
    set<int>v1,v2;
    fill(visited,visited+n,0);
    for(int i=0; i<m; i++){
        cin>>u>>v;
        graph[u-1].push_back(v-1);
        graph[v-1].push_back(u-1);
    }
    stack<node>stek;
    node temp,top;
    temp.index=u-1;
    temp.color=1;
    visited[temp.index]=1;
    v1.insert(u-1);
    stek.push(temp);
    while(!stek.empty()){
        top=stek.top();
        stek.pop();
        for(int i=0; i<graph[top.index].size(); i++){
            v=graph[top.index][i];
            if(!visited[v]){
                visited[v]=1;
                temp.color=!top.color;
                temp.index=v;
                marked[v]=temp.color;
                stek.push(temp);
                if(temp.color)
                    v1.insert(v);
                else
                    v2.insert(v);
            }
            else if(top.color==marked[v]){
                cout<<"-1";
                return 0;
            }
        }
    }
    cout<<v1.size()<<endl;
    set<int>::iterator it;
    it=v1.begin();
    while(it!=v1.end()){
        cout<<*it+1<<" ";
        it++;
    }
    cout<<endl;
    cout<<v2.size()<<endl;
    it=v2.begin();
    while(it!=v2.end()){
        cout<<*it+1<<" ";
        it++;
    }

return 0;}


#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <iomanip>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <sstream>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <ctime>

using namespace std;

struct node{
int color;
int index;
};

int main(){
    int n,m,u,v;
    cin>>n>>m;
    int marked[n],visited[n];
    vector<vector<int> >graph(n);
    set<int>v1,v2;
    fill(visited,visited+n,0);
    for(int i=0; i<m; i++){
        cin>>u>>v;
        graph[u-1].push_back(v-1);
        graph[v-1].push_back(u-1);
    }
    stack<node>stek;
    node temp,top;
    temp.index=u-1;
    temp.color=0;
    visited[temp.index]=1;
    marked[temp.index]=0;
    v2.insert(u-1);
    stek.push(temp);
    while(!stek.empty()){
        top=stek.top();
        stek.pop();
        for(int i=0; i<graph[top.index].size(); i++){
            v=graph[top.index][i];
            if(!visited[v]){
                visited[v]=1;
                temp.color=!top.color;
                temp.index=v;
                marked[v]=temp.color;
                stek.push(temp);
                if(temp.color)
                    v1.insert(v);
                else
                    v2.insert(v);
            }
            else if(top.color==marked[v]){
                cout<<"-1";
                return 0;
            }
        }
    }
    cout<<v1.size()<<endl;
    set<int>::iterator it;
    it=v1.begin();
    while(it!=v1.end()){
        cout<<*it+1<<" ";
        it++;
    }
    cout<<endl;
    cout<<v2.size()<<endl;
    it=v2.begin();
    while(it!=v2.end()){
        cout<<*it+1<<" ";
        it++;
    }

return 0;}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <list>
#include <deque>
#include <map>
#include <queue>using namespace std;
typedef long long ll;
typedef long double ld;
const int INF = 0x3f3f3f3f;
// & 0x7FFFFFFF
const int seed = 131;
const ll INF64 = ll(1e18);
const int maxn = 1e5 + 10;
int T,n,m, color[maxn];
vector<int> g[maxn];
bool ok(int u) {
    int len = g[u].size();
    for(int i = 0; i < len; i++) {
        int v = g[u][i];
        if(color[v] == color[u]) return false;
        if(!color[v]) {
            color[v] = 3 - color[u];
            if(!ok(v)) return false;
        }
    }
    return true;
}
int u, v;
int main() {
    scanf("%d%d", &n, &m);
    for(int i = 0; i < m; i++) {
        scanf("%d%d", &u, &v);
        g[u].push_back(v);
        g[v].push_back(u);
    }
    bool flage = true;
    for(int i = 1; i <= n; i++) {
        if(!color[i]) {
            color[i] = 1;
            if(!ok(i)) {
                flage = false; break;
            }
        }
    }
    if(!flage) {
        printf("-1\n");
        return 0;
    }
    vector<int> ans1, ans2;
    for(int i = 1; i <= n; i++) {

        if(color[i] == 1) ans1.push_back(i);
        else ans2.push_back(i);

    }
    int len = ans1.size();
    printf("%d\n", len);
    for(int i = 0; i < len; i++) {
        printf("%d%c", ans1[i], i == len-1 ? '\n' : ' ');
    }
    len = ans2.size();
    printf("%d\n", len);
    for(int i = 0; i < len; i++) {
        printf("%d%c", ans2[i], i == len-1 ? '\n' : ' ');
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#define N 100010
#define pb push_back
using namespace std;
vector<int> a[N],ans[3];
int n,m,col[N],du[N],cnt;
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		du[u]++,du[v]++;
		a[u].pb(v);a[v].pb(u);
	}
	queue<int> q;
	memset(col,0,sizeof(col));
	for (int i=1;i<=n;i++) if (!du[i]) cnt++;
	while (cnt<n) {
		int x;
		for (x=1;x<=n&&((!du[x])||(col[x]));x++) ;
		col[x]=1;q.push(x);cnt++;
		while (!q.empty()) {
			int u=q.front();q.pop();
			for (int i=0;i<a[u].size();i++) {
				if (!col[a[u][i]]) {
					col[a[u][i]]=3-col[u];
					q.push(a[u][i]);
					cnt++;
				}
				else if (col[a[u][i]]==col[u]) {
					printf("-1\n");
					return 0;
				}
			}
		}
	}
	for (int i=1;i<=n;i++) ans[col[i]].pb(i);
	for (int i=1;i<=2;i++) {
		printf("%d\n",ans[i].size());
		for (int j=0;j<ans[i].size();j++) printf("%d ",ans[i][j]);
		printf("\n");
	}
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double ld;
// & 0x7FFFFFFF
const int maxn = 1e5 + 10;
int T,n,m, color[maxn];
vector<int> g[maxn];
bool ok(int u) {
    int len = g[u].size();
    for(int i = 0; i < len; i++) {
        int v = g[u][i];
        if(color[v] == color[u]) return false;
        if(!color[v]) {
            color[v] = 3 - color[u];
            if(!ok(v)) return false;
        }
    }
    return true;
}
int u, v;
int main() {
    scanf("%d%d", &n, &m);
    for(int i = 0; i < m; i++) {
        scanf("%d%d", &u, &v);
        g[u].push_back(v);
        g[v].push_back(u);
    }
    bool flage = true;
    for(int i = 1; i <= n; i++) {
        if(!color[i]) {
            color[i] = 1;
            if(!ok(i)) {
                flage = false; break;
            }
        }
    }
    if(!flage) {
        printf("-1\n");
        return 0;
    }
    vector<int> ans1, ans2;
    for(int i = 1; i <= n; i++) {

        if(color[i] == 1) ans1.push_back(i);
        else ans2.push_back(i);

    }
    int len = ans1.size();
    printf("%d\n", len);
    for(int i = 0; i < len; i++) {
        printf("%d%c", ans1[i], i == len-1 ? '\n' : ' ');
    }
    len = ans2.size();
    printf("%d\n", len);
    for(int i = 0; i < len; i++) {
        printf("%d%c", ans2[i], i == len-1 ? '\n' : ' ');
    }
    return 0;
}