using System;
using System.Collections.Generic;

/*
The first line contains integer t (1≤t≤100) — the number of test cases in the input. Then test cases follow.

The first line of each of t test sets contains a single integer n (2≤n≤10) — the number of Polycarp's bank cards.
The next n lines contain the PIN codes p1,p2,…,pn — one per line. The length of each of them is 4.
All PIN codes consist of digits only.

input
3
2
1234
0600
2
1337
1337
4
3139
3139
3139
3139

output
0
1234
0600
1
1337
1237
3
3139
3138
3939
6139
*/

public class PinCode{
    static void Main(string[] args){
        PinSolve();
    }

    static void PinSolve(){
        int t = int.Parse(Console.ReadLine());
        int[][] p = new int[t][];

        //gets the pins from each "chunk"
        for(int i = 0; i < t; i++){
            int chunk = int.Parse(Console.ReadLine());
            int[] buffer = new int[chunk];
            for(int x = 0; x < chunk; x++){
                buffer[x] = int.Parse(Console.ReadLine());
            }
            p[i] = buffer;
        }
        //Retrieving data complete

        //^^ DEFINITELY WORKS

        //Iterating through each pin group
        for(int i = 0; i < p.Length; i++){
            int[] pins = p[i];

            //what to do for each pin array
            int changes = 0;

            while(!Distinct(pins)){
                for(int x = 0; x < pins.Length; x ++){
                    int current = pins[x];
                    //Compares one value with every other value above it (so no repeats with values below it)
                    //VV These are all the values above it
                    for(int y = x + 1; y < pins.Length; y ++){
                        //Same number Detected
                        //Changes the upper number because the lower number will not be checked any more
                        if(current == pins[y]){
                            changes++;
                            pins[y] = GetDistinct(pins[y], pins);
                        }
                    }
                }
            }
            //everything is distinct
            Console.WriteLine(changes);
            for(int x = 0; x < pins.Length; x++){
                Console.WriteLine(FormatToPin(pins[x]));
            }
        }
    }

    static string FormatToPin(int n){
        string str = n.ToString();
        while(str.Length < 4){
            str = "0" + str;
        }
        return str;
    }

    //returns a distinct 4 digit int
    static int GetDistinct(int input, int[] arr){
        //Cycles through digits (dynamic as 0060 becomes 60 - 2 digit), and 0-9 different possible changes for them
        int digits = input.ToString().Length;
        for(int d = 0; d < digits; d++){ //d meaning digit
            for(int i = 0; i < 10; i ++){
                if(i == GetDigit(input, d + 1))
                    continue;
                int attempt = ChangeDigit(input, d + 1, i); //cycles through the digit
                if(!Array.Exists(arr, e => e == attempt)) {//is distinct
                    return attempt;
                }
            }
        }
        return -1;
    }

    //a bit hacky but gets the job done
    static int GetDigit(int n, int d){
        string str = n.ToString();
        return int.Parse(str[d - 1].ToString());
    }

    static int ChangeDigit(int n, int d, int val){
        string str = n.ToString();
        str = str.Substring(0,d - 1) + val.ToString() + str.Substring(d);
        return int.Parse(str);
    }

    static bool Distinct(int[] arr){
        for(int i = 0; i < arr.Length; i++){
            int n = arr[i];
            for(int x = i + 1; x < arr.Length; x++){
                if (n == arr[x])
                    return false;
            }
        }
        return true;
    }
}


using System;
using System.Collections.Generic;

/*
The first line contains integer t (1≤t≤100) — the number of test cases in the input. Then test cases follow.

The first line of each of t test sets contains a single integer n (2≤n≤10) — the number of Polycarp's bank cards.
The next n lines contain the PIN codes p1,p2,…,pn — one per line. The length of each of them is 4.
All PIN codes consist of digits only.

input
3
2
1234
0600
2
1337
1337
4
3139
3139
3139
3139

output
0
1234
0600
1
1337
1237
3
3139
3138
3939
6139
*/

public class PinCode{
    static void Main(string[] args){
        PinSolve();
    }

    static void PinSolve(){
        int t = int.Parse(Console.ReadLine());
        int[][] p = new int[][t];

        //gets the pins from each "chunk"
        for(int i = 0; i < t i++){
            int chunk = int.Parse(Console.ReadLine());
            int[] buffer = new int[chunk];
            for(int x = 0; x < chunk; x++){
                buffer[x] = int.Parse(Console.ReadLine());
            }
            p[i] = buffer;
        }
        //Retrieving data complete

        //Iterating through each pin group
        for(int i = 0; i < p.Length; i++){
            int[] pins = p[i];

            //what to do for each pin array
            Array.Sort(pins.Sort());

            int changes = 0;

            while(!Distinct(pins)){
                for(int i = 0; i < pins.Length; i ++){
                    int current = pins[i];
                    //Compares one value with every other value above it (so no repeats with values below it)
                    //VV These are all the values above it
                    for(int x = i + 1; i < pins.Length; x ++){
                        //Same number Detected
                        //Changes the upper number because the lower number will not be checked any more
                        if(current == pins[x]){
                            changes++;
                            pins[x] = GetDistinct(pins[x], in pins);
                        }
                    }
                }
            }
            //everything is distinct
            Console.WriteLine(changes);
            for(int i = 0; i < pins.Length; i++){
                Console.WriteLine(FormatToPin(pins[i]));
            }
        }
    }

    static string FormatToPin(int n){
        string str = n.ToString();
        while(str.Length < 4){
            str = "0" + str;
        }
        return str;
    }

    //returns a distinct 4 digit int
    static int GetDistinct(int input, in int[] arr){
        //Cycles through digits (dynamic as 0060 becomes 60 - 2 digit), and 0-9 different possible changes for them
        int digits = input.ToString().Length;
        for(int d = 0; i < digits; d++){ //d meaning digit
            for(int i = 0; i < 10; i ++){
                if(i == GetDigit(input, d))
                    continue;
                int attempt = ChangeDigit(input, d, i); //cycles through the digit
                if(!Array.Exists(arr, e => e == attempt)) {//is distinct
                    return attempt;
                }
            }
        }
        return -1;
    }

    //a bit hacky but gets the job done
    static int GetDigit(int n, int d){
        string str = n.ToString();
        return int.Parse(str[d - 1]);
    }

    static int ChangeDigit(int n, int d, int val){
        string str = n.ToString();
        str = str.Substring(0,d - 1) + val.ToString() + str.Substring(d);
        return int.Parse(str);
    }

    static bool Distinct(int[] arr){
        for(int i = 0; i < arr.Length; i++){
            int n = arr[i];
            for(int x = i + 1; x < arr.Length; x++){
                if (n == arr[x])
                    return false;
            }
        }
        return true;
    }
}


using System;
using System.Collections.Generic;

/*
The first line contains integer t (1≤t≤100) — the number of test cases in the input. Then test cases follow.

The first line of each of t test sets contains a single integer n (2≤n≤10) — the number of Polycarp's bank cards.
The next n lines contain the PIN codes p1,p2,…,pn — one per line. The length of each of them is 4.
All PIN codes consist of digits only.

input
3
2
1234
0600
2
1337
1337
4
3139
3139
3139
3139

output
0
1234
0600
1
1337
1237
3
3139
3138
3939
6139
*/

public class PinCode{
    static void Main(string[] args){
        PinSolve();
    }

    static void PinSolve(){
        int t = int.Parse(Console.ReadLine());
        int[][] p = new int[t][];

        //gets the pins from each "chunk"
        for(int i = 0; i < t; i++){
            int chunk = int.Parse(Console.ReadLine());
            int[] buffer = new int[chunk];
            for(int x = 0; x < chunk; x++){
                buffer[x] = int.Parse(Console.ReadLine());
            }
            p[i] = buffer;
        }
        //Retrieving data complete

        //^^ DEFINITELY WORKS

        //Iterating through each pin group
        for(int i = 0; i < p.Length; i++){
            int[] pins = p[i];

            //what to do for each pin array
            Array.Sort(pins);

            int changes = 0;

            while(!Distinct(pins)){
                for(int x = 0; x < pins.Length; x ++){
                    Console.WriteLine($"x:{x}");
                    int current = pins[x];
                    //Compares one value with every other value above it (so no repeats with values below it)
                    //VV These are all the values above it
                    for(int y = x + 1; y < pins.Length; y ++){
                        Console.WriteLine($"y:{y}");
                        //Same number Detected
                        //Changes the upper number because the lower number will not be checked any more
                        if(current == pins[y]){
                            changes++;
                            pins[y] = GetDistinct(pins[y], pins);
                        }
                    }
                }
            }
            //everything is distinct
            Console.WriteLine(changes);
            for(int x = 0; x < pins.Length; x++){
                Console.WriteLine(FormatToPin(pins[x]));
            }
        }
    }

    static string FormatToPin(int n){
        string str = n.ToString();
        while(str.Length < 4){
            str = "0" + str;
        }
        return str;
    }

    //returns a distinct 4 digit int
    static int GetDistinct(int input, int[] arr){
        Console.WriteLine($"GetDistinct({input})...");
        //Cycles through digits (dynamic as 0060 becomes 60 - 2 digit), and 0-9 different possible changes for them
        int digits = input.ToString().Length;
        for(int d = 0; d < digits; d++){ //d meaning digit
            for(int i = 0; i < 10; i ++){
                if(i == GetDigit(input, d))
                    continue;
                int attempt = ChangeDigit(input, d, i); //cycles through the digit
                if(!Array.Exists(arr, e => e == attempt)) {//is distinct
                    Console.WriteLine($"New input : {attempt}..."); //DELETETHIS
                    return attempt;
                }
            }
        }
        return -1;
    }

    //a bit hacky but gets the job done
    static int GetDigit(int n, int d){
        Console.WriteLine($"Getting digit {d} from {n}..")
        string str = n.ToString();
        Console.WriteLine($"It is {str[d - 1]}!");
        return int.Parse(str[d - 1].ToString());
    }

    static int ChangeDigit(int n, int d, int val){
        string str = n.ToString();
        str = str.Substring(0,d - 1) + val.ToString() + str.Substring(d);
        return int.Parse(str);
    }

    static bool Distinct(int[] arr){
        for(int i = 0; i < arr.Length; i++){
            int n = arr[i];
            for(int x = i + 1; x < arr.Length; x++){
                if (n == arr[x])
                    return false;
            }
        }
        return true;
    }
}


using System;

class Program
{
    public static void printnum(int x)
    {
        if(x < 1000)
        {
            Console.Write(0);
        }
        if (x < 100)
        {
            Console.Write(0);
        }
        if (x < 10)
        {
            Console.Write(0);
        }
        Console.WriteLine(x);
    }
    static void Main(string[] args)
    {
        var q = int.Parse(Console.ReadLine());
        while(q-->0)
        {
            var num = new int[10000];
            var n = int.Parse(Console.ReadLine());
            var a = new int[n];
            for(int i = 0; i < n; i++)
            {
                a[i] = int.Parse(Console.ReadLine());
                num[a[i]]++;
            }
            var ans = 0;
            for (int i = 0; i < n; i++)
            {
                if(num[a[i]] == 1)
                {
                    continue;
                }
                ans++;
                for(int x = 0; x < 10; x++)
                {
                    if(num[a[i] - a[i]%10 + x] == 0)
                    {
                        num[a[i]]--;
                        num[a[i] - a[i] % 10 + x]++;
                        a[i] = a[i] - a[i] % 10 + x;
                        break;
                    }
                }
            }
            Console.WriteLine(ans);
            for (int i = 0; i < n; i++)
            {
                printnum(a[i]);
            }
        }

    }
}


using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

class MyClass
{
    public static void Solve()
    {
        var t = int.Parse(Console.ReadLine());
        for (int _i = 0; _i < t; _i++)
        {
            var N = int.Parse(Console.ReadLine());
            var list = new List<string>();
            for (int i = 0; i < N; i++)
            {
                var pin = Console.ReadLine();
                list.Add(pin);
            }
            var k = N - list.Distinct().Count();
            var ans = new List<string>();
            for (int i = 0; i < N; i++)
            {
                var S = list[i];
                if (!ans.Contains(S))
                {
                    ans.Add(S);
                }
                else
                {
                    for (int j = 0; j < 10; j++)
                    {
                        var T = string.Format("{0}{1}{2}{3}", S[0], S[1], S[2], j);
                        if (S != T && !list.Contains(T))
                        {
                            list.Add(T);
                            ans.Add(T);
                            break;
                        }
                        T = string.Format("{0}{1}{2}{3}", j, S[1], S[2], S[3]);
                        if (S != T && !list.Contains(T))
                        {
                            list.Add(T);
                            ans.Add(T);
                            break;
                        }
                    }
                }
            }
            Console.WriteLine(k);
            foreach (var item in ans)
            {
                Console.WriteLine(item);
            }
        }
    }

    public static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;
using Library;

namespace Program
{
    public static class CODEFORCES2
    {
        static public int numberOfRandomCases = 0;
        static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker)
        {
        }
        static public void Solve()
        {
            var t = NN;
            for (var i = 0; i < t; i++)
            {
                var n = NN;
                var pList = NSList(n);
                var k = pList.GroupBy(e => e).Sum(e => e.Count() - 1);
                for (var j = 0; j < n; j++)
                {
                    var cnt = pList.Count(e => e == pList[j]);
                    if (cnt > 1)
                    {
                        for (var x = 0; x < 10; x++)
                        {
                            var tmp = pList[j].ToArray();
                            tmp[0] = (char)(x + '0');
                            var str = new string(tmp);
                            if (pList.Count(e => e == str) == 0)
                            {
                                pList[j] = str;
                                break;
                            }
                        }
                    }
                }
                Console.WriteLine(k);
                foreach (var item in pList)
                {
                    Console.WriteLine(item);
                }
            }
        }
        static class Console_
        {
            static Queue<string> param = new Queue<string>();
            public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); }
        }
        class Printer : StreamWriter
        {
            public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
            public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; }
            public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; }
        }
        static public void Main(string[] args) { if (args.Length == 0) { Console.SetOut(new Printer(Console.OpenStandardOutput())); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); }
        static long NN => long.Parse(Console_.NextString());
        static double ND => double.Parse(Console_.NextString());
        static string NS => Console_.NextString();
        static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
        static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
        static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
        static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift);
        static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred);
        static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n);
        static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c);
        static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } }
        static IEnumerator<uint> _xsi = _xsc();
        static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } }
    }
}
namespace Library {
}


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

int dfs(vector<int> adj[], int u, int freq[], int val[], int prev){
    if(freq[u]==0){
            freq[u]=1;
            val[u]=prev%2;
            for( int i = 0 ; i < adj[u].size() ; i++ ){
                if(dfs(adj,adj[u][i],freq,val,(prev+1)%2)==0){
                    return 0;
                }
            }
    }
    else if(freq[u]==1&&val[u]!=prev%2){
        return 0;
    }
    return 1;
}

int main()
{
    int n,m,i,flag=0,freq[100005]={0},val[n+5],temp=0;
    cin>>n>>m;
    vector<int> adj[n+5];
    for(int i=0;i<m;i++){
        int u,v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(i=1;i<=n;i++){
        if(freq[i]==0){
            if(dfs(adj,i,freq,val,0)==0){
                if(n==100000&&m==100000){
                    cout<<i<<" "<<val[i]<<endl;
                }
                cout<<-1;
                exit(0);
            }
        }
    }
    for(i=1;i<=n;i++){
        if(val[i]==1){
            temp++;
        }
    }
    cout<<temp<<endl;
    for(i=1;i<=n;i++){
        if(val[i]==1){
            cout<<i<<" ";
        }
    }
    cout<<endl<<n-temp<<endl;
    for(i=1;i<=n;i++){
        if(val[i]==0){
            cout<<i<<" ";
        }
    }
    cout<<endl;
}


#include <bits/stdc++.h>
#define ll long long int
using namespace std;

int dfs(vector<ll> adj[], ll u, bool vis[], bool prev, bool ans[]){
    if(vis[u]==false){
        vis[u]=true;
        ans[u]=prev;
        for(ll i=0; i<adj[u].size();i++){
            if(dfs(adj,adj[u][i],vis,!prev,ans)==0){
                return 0;
            }
        }
    }
    else if(vis[u]==true&&prev!=ans[u]){
        return 0;
    }
    else
        return 1;
}

int main(){
    ll n,m,i,u,v;
    cin>>n>>m;
    vector<ll> adj[n+5];
    bool vis[n+5]={false},ans[n+5]={false};
    for(i=0;i<m;i++){
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    if(dfs(adj,1,vis,false,ans)==0){
        cout<<-1;
        exit(0);
    }
    else{
        ll countt=0;
        for(i=1;i<=n;i++){
            if(ans[i]==false){
                countt++;
            }
        }
        cout<<countt<<endl;
        for(i=1;i<=n;i++){
            if(ans[i]==false){
                cout<<i<<" ";
            }
        }
        cout<<endl<<n-countt<<endl;;
        for(i=1;i<=n;i++){
            if(ans[i]==true){
                cout<<i<<" ";
            }
        }
    }
}


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

int dfs(vector<int> adj[], int u, int freq[], int val[], int prev){
    if(freq[u]==0){
            freq[u]=1;
            val[u]=prev%2;
            for( int i = 0 ; i < adj[u].size() ; i++ ){
                if(dfs(adj,adj[u][i],freq,val,(prev+1)%2)==0){
                    return 0;
                }
            }
    }
    else if(freq[u]==1&&val[u]!=prev%2){
        return 0;
    }
    return 1;
}

int main()
{
    int n,m,i,flag=0,freq[100005]={0},val[n+5],temp=0;
    cin>>n>>m;
    vector<int> adj[n+5];
    for(int i=0;i<m;i++){
        int u,v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(i=1;i<=n;i++){
        if(freq[i]==0){
            if(dfs(adj,i,freq,val,0)==0){
                cout<<-1;
                exit(0);
            }
        }
    }
    for(i=1;i<=n;i++){
        if(val[i]==1){
            temp++;
        }
    }
    cout<<temp<<endl;
    for(i=1;i<=n;i++){
        if(val[i]==1){
            cout<<i<<" ";
        }
    }
    cout<<endl<<n-temp<<endl;
    for(i=1;i<=n;i++){
        if(val[i]==0){
            cout<<i<<" ";
        }
    }
    cout<<endl;
}


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

int dfs(vector<int> adj[], int u, int freq[], int val[], int prev){
    if(freq[u]==0){
            freq[u]=1;
            val[u]=prev%2;
            for( int i = 0 ; i < adj[u].size() ; i++ ){
                if(dfs(adj,adj[u][i],freq,val,prev+1)==0){
                    return 0;
                }
            }
    }
    else if(freq[u]==1&&val[u]!=prev%2){
        return 0;
    }
    return 1;
}

int main()
{
    int n,m,i,flag=0,freq[100005]={0},val[n+5],temp=0;
    cin>>n>>m;
    vector<int> adj[n+5];
    for(int i=0;i<m;i++){
        int u,v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(i=1;i<=n;i++){
        if(freq[i]==0){
            if(dfs(adj,i,freq,val,0)==0){
                cout<<-1;
                exit(0);
            }
        }
    }
    for(i=1;i<=n;i++){
        if(val[i]==1){
            temp++;
        }
    }
    cout<<temp<<endl;
    for(i=1;i<=n;i++){
        if(val[i]==1){
            cout<<i<<" ";
        }
    }
    cout<<endl<<n-temp<<endl;
    for(i=1;i<=n;i++){
        if(val[i]==0){
            cout<<i<<" ";
        }
    }
    cout<<endl;
}


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

int dfs(vector<int> adj[], int u, int freq[], int val[], int prev){
    if(freq[u]==0){
            freq[u]=1;
            val[u]=prev%2;
            for( int i = 0 ; i < adj[u].size() ; i++ ){
                if(dfs(adj,adj[u][i],freq,val,(prev+1)%2)==0){
                    return 0;
                }
            }
            freq[u]=0;
    }
    else if(freq[u]==1&&val[u]!=prev%2){
        return 0;
    }
    return 1;
}

int main()
{
    int n,m,i,flag=0,freq[100005]={0},val[n+5],temp=0;
    cin>>n>>m;
    vector<int> adj[n+5];
    for(int i=0;i<m;i++){
        int u,v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(i=1;i<=n;i++){
        if(freq[i]==0){
            if(dfs(adj,i,freq,val,0)==0){
                cout<<-1;
                exit(0);
            }
        }
    }
    for(i=1;i<=n;i++){
        if(val[i]==1){
            temp++;
        }
    }
    cout<<temp<<endl;
    for(i=1;i<=n;i++){
        if(val[i]==1){
            cout<<i<<" ";
        }
    }
    cout<<endl<<n-temp<<endl;
    for(i=1;i<=n;i++){
        if(val[i]==0){
            cout<<i<<" ";
        }
    }
    cout<<endl;
}


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

int dfs(vector<int> adj[], int u, int freq[], int val[], int prev){
    if(freq[u]==0){
            freq[u]=1;
            val[u]=prev%2;
            for( int i = 0 ; i < adj[u].size() ; i++ ){
                if(dfs(adj,adj[u][i],freq,val,(prev+1)%2)==0){
                    return 0;
                }
            }
    }
    else if(freq[u]==1&&val[u]!=prev%2){
        if(n==100000&&m==100000){
            cout<<u<<" "<<freq[u]<<" "<<prev<<endl;
        }
        return 0;
    }
    return 1;
}

int main()
{
    int n,m,i,flag=0,freq[100005]={0},val[n+5],temp=0;
    cin>>n>>m;
    vector<int> adj[n+5];
    for(int i=0;i<m;i++){
        int u,v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(i=1;i<=n;i++){
        if(freq[i]==0){
            if(dfs(adj,i,freq,val,0)==0){
                cout<<-1;
                exit(0);
            }
        }
    }
    for(i=1;i<=n;i++){
        if(val[i]==1){
            temp++;
        }
    }
    cout<<temp<<endl;
    for(i=1;i<=n;i++){
        if(val[i]==1){
            cout<<i<<" ";
        }
    }
    cout<<endl<<n-temp<<endl;
    for(i=1;i<=n;i++){
        if(val[i]==0){
            cout<<i<<" ";
        }
    }
    cout<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define N 100011
vector<int> g[N];
int n,m;

bool dfs(int *marked ,int s,int st)
{
  int i;
  marked[s]=st;
  for(i=0;i<g[s].size();i++)
    {
      int t=g[s][i];
      if(marked[t]==-1)
	{
	  if(dfs(marked,t,1-st)==false)
	    return false;
	  else continue;
	  //  edgeto[*it]=s;

	}
      if(marked[t]!=1-st)
	return false;

    }
  return true;

}

int main()
{
  int i;
  scanf("%d %d ",&m,&n);
  int *marked;
  marked=(int *)malloc((m+1)*sizeof(int));
  //  int edgeto[m+1];
  for(i=0;i<=m;i++)
    {
      marked[i]=-1;
      //   edgeto[i]=-1;
    }
  for(i=0;i<n;i++)
    {
      int x,y;
      scanf("%d %d",&x,&y);
      g[x].push_back(y);
      g[y].push_back(x);
    }

  marked[1]=0;
  bool bi=dfs(marked,1,0);
  int zc=0,oc=0;
  if(bi==false)
    {
      printf("-1\n");
      return 0;
    }
  for(i=1;i<=m;i++)
    {
      if(marked[i]==0)
	zc++;
      else if(marked[i]==1)
	oc++;
    }
  printf("%d\n",oc);
  for(i=1;i<=m;i++)
    if(marked[i]==1)
      printf("%d ",i);

  printf("\n%d\n",zc);
  for(i=1;i<=m;i++)
    if(marked[i]==0)
      printf("%d ",i);
  free(marked);
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define N 924567
vector<int> g[N];
int n,m;

bool dfs(int marked[] ,int s,int st)
{
  for(std::vector<int>::iterator it=g[s].begin();it!=g[s].end();++it)
    {
      if(marked[*it]==-1)
	{
	  marked[*it]=1-st;
	  if(dfs(marked,*it,1-st)==false)
	    return false;
	  else continue;
	  //  edgeto[*it]=s;

	}
      if(marked[*it]!=1-st)
	return false;

    }
  return true;

}

int main()
{
  int i;
  scanf("%d %d ",&m,&n);
  int marked[m+1];
  //  int edgeto[m+1];
  for(i=0;i<=m;i++)
    {
      marked[i]=-1;
      //   edgeto[i]=-1;
    }
  for(i=0;i<n;i++)
    {
      int x,y;
      scanf("%d %d",&x,&y);
      g[x].push_back(y);
      g[y].push_back(x);
    }

  marked[1]=0;
  bool bi=dfs(marked,1,0);
  int zc=0,oc=0;
  if(bi==false)
    {
      printf("-1\n");
      return 0;
    }
  for(i=1;i<=m;i++)
    {
      if(marked[i]==0)
	zc++;
      else if(marked[i]==1)
	oc++;
    }
  printf("%d\n",oc);
  for(i=1;i<=m;i++)
    if(marked[i]==1)
      printf("%d ",i);

  printf("\n%d\n",zc);
  for(i=1;i<=m;i++)
    if(marked[i]==0)
      printf("%d ",i);

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define N 924567
vector<int> g[N];
int n,m;

bool dfs(int *marked ,int s,int st)
{
  for(std::vector<int>::iterator it=g[s].begin();it!=g[s].end();it++)
    {
      if(marked[*it]==-1)
	{
	  marked[*it]=1-st;
	  if(dfs(marked,*it,1-st)==false)
	    return false;
	  else continue;
	  //  edgeto[*it]=s;

	}
      if(marked[*it]!=1-st)
	return false;

    }
  return true;

}

int main()
{
  int i;
  scanf("%d %d ",&m,&n);
  int *marked;
  marked=(int *)malloc((m+1)*sizeof(int));
  //  int edgeto[m+1];
  for(i=0;i<=m;i++)
    {
      marked[i]=-1;
      //   edgeto[i]=-1;
    }
  for(i=0;i<n;i++)
    {
      int x,y;
      scanf("%d %d",&x,&y);
      g[x].push_back(y);
      g[y].push_back(x);
    }

  marked[1]=0;
  bool bi=dfs(marked,1,0);
  int zc=0,oc=0;
  if(bi==false)
    {
      printf("-1\n");
      return 0;
    }
  for(i=1;i<=m;i++)
    {
      if(marked[i]==0)
	zc++;
      else if(marked[i]==1)
	oc++;
    }
  printf("%d\n",oc);
  for(i=1;i<=m;i++)
    if(marked[i]==1)
      printf("%d ",i);

  printf("\n%d\n",zc);
  for(i=1;i<=m;i++)
    if(marked[i]==0)
      printf("%d ",i);

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define M 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define tr(x,it) for(auto it = x.begin();it!=x.end();++it)
#define fpresent(x,c) ((c).find(x) != (c).end())  //set,map
#define present(c,x) (find(all(c),x) != (c).end()) //vector
#define pb push_back
#define mp make_pair
#define setv(ar, val) memset(ar, val, sizeof(ar));
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
#define N 100005
vector<ll> g[N],stat(N);
bool visited[N],flag;

void dfs(int x,int state)
{
	visited[x]=true;
	stat[x]=state;
	for(auto it: g[x])
	{
		if(visited[it]==true and stat[it]==1-state) continue;
		else if(visited[it]==false)
		dfs(it,1-state);
		else flag=false;
	}
}
int main()
{
    // freopen("input.in","r",stdin);
    // freopen("output.in","w",stdout);
    fastio;
    cin.tie(NULL);
    ll n,m,i,j,k,ans=0;
    cin>>n>>m;
    for(i=0;i<m;i++)
    {
    	cin>>j>>k;
    	g[j].pb(k);
    	g[k].pb(j);
    }
    for(i=1;i<=n;i++) visited[i]=false;
    flag=true;
    for(i=1;i<=n;i++)
    	if(visited[i]==false)
    		dfs(i,0);
    vector<ll> ansa,ansb;
    if(flag==false) return cout<<-1<<endl,0;
    for(i=1;i<=n;i++)
    	if(stat[i]==1)
    		ansa.pb(i);
    	else ansb.pb(i);
    cout<<ansa.size()<<endl;
    for(auto it: ansa) cout<<it<<" ";
    	cout<<endl;
    cout<<ansb.size()<<endl;
    for(auto it: ansb) cout<<it<<" ";
    	cout<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define N 924567
vector<int> g[N];
int n,m;

bool dfs(int *marked,int *edgeto ,int s,int st)
{
  for(std::vector<int>::iterator it=g[s].begin();it!=g[s].end();++it)
    {
      if(marked[*it]==-1)
	{
	  marked[*it]=1-st;
	  if(dfs(marked,edgeto,*it,1-st)==false)
	    return false;
	  else continue;
	  edgeto[*it]=s;

	}
      if(marked[*it]!=1-st)
	return false;

    }
  return true;

}

int main()
{
  int s,i;
  scanf("%d %d ",&m,&n);
  int marked[m+1];
  int edgeto[m+1];
  for(i=0;i<=m;i++)
    {
      marked[i]=-1;
      edgeto[i]=-1;
    }
  for(i=0;i<n;i++)
    {
      int x,y;
      scanf("%d %d",&x,&y);
      g[x].push_back(y);
      g[y].push_back(x);
    }

  marked[1]=0;
  bool bi=dfs(marked,edgeto,1,0);
  bool v=true;
  int zc=0,oc=0;
  if(bi==false)
    {
      printf("-1\n");
      return 0;
    }
  for(i=1;i<=m;i++)
    {
      if(marked[i]==0)
	zc++;
      else if(marked[i]==1)
	oc++;
    }
  printf("%d\n",oc);
  for(i=1;i<=m;i++)
    if(marked[i]==1)
      printf("%d ",i);

  printf("\n%d\n",zc);
  for(i=1;i<=m;i++)
    if(marked[i]==0)
      printf("%d ",i);

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define N 924567
vector<int> g[N];
int n,m;

bool dfs(int *marked ,int s,int st)
{
  for(std::vector<int>::iterator it=g[s].begin();it!=g[s].end();++it)
    {
      if(marked[*it]==-1)
	{
	  marked[*it]=1-st;
	  if(dfs(marked,*it,1-st)==false)
	    return false;
	  else continue;
	  //  edgeto[*it]=s;

	}
      if(marked[*it]!=1-st)
	return false;

    }
  return true;

}

int main()
{
  int i;
  scanf("%d %d ",&m,&n);
  int *marked;
  marked=(int *)malloc((m+1)*sizeof(int));
  //  int edgeto[m+1];
  for(i=0;i<=m;i++)
    {
      marked[i]=-1;
      //   edgeto[i]=-1;
    }
  for(i=0;i<n;i++)
    {
      int x,y;
      scanf("%d %d",&x,&y);
      g[x].push_back(y);
      g[y].push_back(x);
    }

  marked[1]=0;
  bool bi=dfs(marked,1,0);
  int zc=0,oc=0;
  if(bi==false)
    {
      printf("-1\n");
      return 0;
    }
  for(i=1;i<=m;i++)
    {
      if(marked[i]==0)
	zc++;
      else if(marked[i]==1)
	oc++;
    }
  printf("%d\n",oc);
  for(i=1;i<=m;i++)
    if(marked[i]==1)
      printf("%d ",i);

  printf("\n%d\n",zc);
  for(i=1;i<=m;i++)
    if(marked[i]==0)
      printf("%d ",i);

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define N 124567
vector<int> g[N];
int n,m;

bool dfs(int *marked,int *edgeto ,int s,int st)
{
  for(std::vector<int>::iterator it=g[s].begin();it!=g[s].end();++it)
    {
      if(marked[*it]==-1)
	{
	  marked[*it]=1-st;
	  if(dfs(marked,edgeto,*it,1-st)==false)
	    return false;
	  else continue;
	  edgeto[*it]=s;

	}
      if(marked[*it]!=1-st)
	return false;

    }
  return true;

}

int main()
{
  int s,i;
  scanf("%d %d ",&m,&n);
  int marked[m+1];
  int edgeto[m+1];
  for(i=0;i<=m;i++)
    {
      marked[i]=-1;
      edgeto[i]=-1;
    }
  for(i=0;i<n;i++)
    {
      int x,y;
      scanf("%d %d",&x,&y);
      g[x].push_back(y);
      g[y].push_back(x);
    }

  marked[1]=0;
  bool bi=dfs(marked,edgeto,1,0);
  bool v=true;
  int zc=0,oc=0;
  if(bi==false)
    {
      printf("-1\n");
      return 0;
    }
  for(i=1;i<=m;i++)
    {
      if(marked[i]==0)
	zc++;
      else if(marked[i]==1)
	oc++;
    }
  printf("%d\n",zc);
  for(i=1;i<=m;i++)
    if(marked[i]==0)
      printf("%d ",i);
  printf("\n%d\n",oc);
  for(i=1;i<=m;i++)
    if(marked[i]==1)
      printf("%d ",i);
  return 0;
}


/****************************************************************************

	" Be the change that you wish to see in the world. "
	-- Mahatma Gandhi

******************************************************************************
*                                                                            *
*                       Author : Dhiraj Govindvira                           *
*                         Date : 27-Mar-2020 ~ Friday                        *
*                         Time : 11:02:44 AM                                 *
*                                                                            *
*****************************************************************************/

#if __has_include("D:/dhiraj/Programming/debug.h") && __has_include(<stdint.h>)
    #include "D:/dhiraj/Programming/debug.h"
#else
    #include <bits/stdc++.h>
    using namespace std;
    #define d(...) 11
#endif

// Data Type ----------------------------------------------------------------

#define ull                 unsigned long long int
#define ll                  long long int
#define ld                  long double

// Loops --------------------------------------------------------------------

#define loop(i,s,e)         for(ll i=(s); i<(e); i++)
#define rloop(i,s,e)        for(ll i=(s); i>=(e); i--)
#define iter(it,var)        for(auto it=var.begin(); it!=var.end(); it++)
#define riter(it,var)       for(auto it=var.rbegin(); it!=var.rend(); it++)

// Stl ----------------------------------------------------------------------

#define pb                  push_back
#define pf                  push_front
#define eb                  emplace_back
#define popb                pop_back
#define popf                pop_front
#define mp                  make_pair
#define mt                  make_tuple
#define ff                  first
#define ss                  second
#define vll                 vector<ll>
#define vvl                 vector<vll>
#define pll                 pair<ll,ll>
#define ub                  upper_bound
#define lb                  lower_bound
#define bs                  binary_search
#define all(x)              x.begin(),x.end()
#define allb(x)             x.begin(),x.begin()
#define rall(x)             x.rbegin(),x.rend()
#define at(ind,tup)         get<ind>(tup)
#define make_unique(x)      sort(all(x)); x.erase(unique(all(x)),x.end())

// Maths --------------------------------------------------------------------

const double PI = 2*acos(0.0);
#define gcd(a,b)            __gcd((a),(b))
#define lcm(a,b)            ((a)/(__gcd((a),(b)))*(b))
#define Log(x,b)            (log(x)/log(b))
#define iNF                 INT_MAX
#define INF                 LLONG_MAX

// Big data -----------------------------------------------------------------

const int Mod = 1E9 + 7;
#define Mul(a,b)            (((a) % Mod)*((b) % Mod)) % Mod
#define Sum(a,b)            (((a) % Mod)+((b) % Mod)) % Mod
#define Sub(a,b)            (((a) % Mod)-((b) % Mod) + Mod) % Mod
#define Div(a,b)            Mul(a,modInverse(b))

// Bit-Manipulation ---------------------------------------------------------

#define Bit(n)              bitset<n>
#define setbit(pos,n)       n |= (1LL<<pos)
#define resetbit(pos,n)     n &= (~(1LL<<pos))
#define toogle(pos,n)       n ^= (1LL<<pos)
#define atpos(pos,n)        ((n&(1LL<<pos))!=0)
#define bits(n)             (floor(log2(n)) + 1)
#define rightone(n)         (__builtin_ffs(n)-1)
#define countone(n)         (__builtin_popcountll(n))
#define parity(n)           (__builtin_parity(n))
#define counttz(n)          (__builtin_ctzll(n))
#define countlz(n)          (__builtin_clzll(n))

// Extra --------------------------------------------------------------------

#define fast                ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define scan(any)           for(auto &i:any) cin>>i;
#define print(any)          for(auto &i:any) cout<<i<<" "; nl;
#define printp(any)         for(auto &i:any) cout<<i.ff<<" "<<i.ss<<endl;
#define precise(a)          cout<<fixed<<setprecision(a)
inline  void yes()          {std::cout<<"Yes\n";}
inline  void no()           {std::cout<<"No\n";}
#define flush               std::cout.flush()
#define nl                  std::cout<<'\n'
#define endl                '\n'

// Template -----------------------------------------------------------------

template <typename T>
inline bool inrange(T a, T l, T r) {
    if(l>r) swap(l,r);
    return (a>=l and a<=r);
}
template <typename T, typename U>
inline bool exist(T val, U &any) {
    return (any.find(val) != any.end());
}
// multiple input
template <typename T>
inline void inp(T &any) {
    cin >> any;
}
template <typename T, typename... U>
inline void inp(T &a,U &...b) {
    cin >> a; inp(b...);
}
// scan vector
template <typename T>
inline istream& operator >> (istream &in, vector<T> &a) {
    for(auto &x : a) in >> x;
    return in;
}
// scan pair
template <typename T, typename U>
inline istream& operator >> (istream &in, pair<T,U> &a) {
    in >> a.ff >> a.ss;
    return in;
}

// Solve --------------------------------------------------------------------

using graph = vector<vector<ll>>;
void solve(ll &T)
{
    ll n, m;
    std::cin>>n>>m;

    graph g(n);
    loop(i,0,m)
    {
        ll x, y;
        std::cin>>x>>y;
        x--, y--;
        g[x].eb(y);
    }

    set<ll> s1, s2;
    loop(i,0,n)
    {
        for(auto adj : g[i])
        {
            ll x = i + 1;
            ll y = adj + 1;

            if((exist(x,s1) and exist(y,s1)) or (exist(x,s2) and exist(y,s2)))
            {
                std::cout<<-1;
                return;
            }
            else if(exist(x,s1)) s2.emplace(y);
            else if(exist(y,s1)) s2.emplace(x);
            else if(exist(y,s2)) s1.emplace(x);
            else if(exist(x,s2)) s1.emplace(y);
            else
            {
                s1.emplace(x);
                s2.emplace(y);
            }
        }
    }
    std::cout<<s1.size(); nl;
    print(s1);

    std::cout<<s2.size(); nl;
    print(s2);
}

// Main ---------------------------------------------------------------------

int main()
{
    #ifdef Dhiraj
        freopen("D:/dhiraj/Programming/i1.txt","r",stdin);
        freopen("D:/dhiraj/Programming/o1.txt","w",stdout);
    #endif

    fast;
    int t = 1;
    loop(i,1,t+1)
    solve(i);
    return 0;
}


/****************************************************************************

	" Be the change that you wish to see in the world. "
	-- Mahatma Gandhi

******************************************************************************
*                                                                            *
*                       Author : Dhiraj Govindvira                           *
*                         Date : 27-Mar-2020 ~ Friday                        *
*                         Time : 11:02:44 AM                                 *
*                                                                            *
*****************************************************************************/

#if __has_include("D:/dhiraj/Programming/debug.h") && __has_include(<stdint.h>)
    #include "D:/dhiraj/Programming/debug.h"
#else
    #include <bits/stdc++.h>
    using namespace std;
    #define d(...) 11
#endif

// Data Type ----------------------------------------------------------------

#define ull                 unsigned long long int
#define ll                  long long int
#define ld                  long double

// Loops --------------------------------------------------------------------

#define loop(i,s,e)         for(ll i=(s); i<(e); i++)
#define rloop(i,s,e)        for(ll i=(s); i>=(e); i--)
#define iter(it,var)        for(auto it=var.begin(); it!=var.end(); it++)
#define riter(it,var)       for(auto it=var.rbegin(); it!=var.rend(); it++)

// Stl ----------------------------------------------------------------------

#define pb                  push_back
#define pf                  push_front
#define eb                  emplace_back
#define popb                pop_back
#define popf                pop_front
#define mp                  make_pair
#define mt                  make_tuple
#define ff                  first
#define ss                  second
#define vll                 vector<ll>
#define vvl                 vector<vll>
#define pll                 pair<ll,ll>
#define ub                  upper_bound
#define lb                  lower_bound
#define bs                  binary_search
#define all(x)              x.begin(),x.end()
#define allb(x)             x.begin(),x.begin()
#define rall(x)             x.rbegin(),x.rend()
#define at(ind,tup)         get<ind>(tup)
#define make_unique(x)      sort(all(x)); x.erase(unique(all(x)),x.end())

// Maths --------------------------------------------------------------------

const double PI = 2*acos(0.0);
#define gcd(a,b)            __gcd((a),(b))
#define lcm(a,b)            ((a)/(__gcd((a),(b)))*(b))
#define Log(x,b)            (log(x)/log(b))
#define iNF                 INT_MAX
#define INF                 LLONG_MAX

// Big data -----------------------------------------------------------------

const int Mod = 1E9 + 7;
#define Mul(a,b)            (((a) % Mod)*((b) % Mod)) % Mod
#define Sum(a,b)            (((a) % Mod)+((b) % Mod)) % Mod
#define Sub(a,b)            (((a) % Mod)-((b) % Mod) + Mod) % Mod
#define Div(a,b)            Mul(a,modInverse(b))

// Bit-Manipulation ---------------------------------------------------------

#define Bit(n)              bitset<n>
#define setbit(pos,n)       n |= (1LL<<pos)
#define resetbit(pos,n)     n &= (~(1LL<<pos))
#define toogle(pos,n)       n ^= (1LL<<pos)
#define atpos(pos,n)        ((n&(1LL<<pos))!=0)
#define bits(n)             (floor(log2(n)) + 1)
#define rightone(n)         (__builtin_ffs(n)-1)
#define countone(n)         (__builtin_popcountll(n))
#define parity(n)           (__builtin_parity(n))
#define counttz(n)          (__builtin_ctzll(n))
#define countlz(n)          (__builtin_clzll(n))

// Extra --------------------------------------------------------------------

#define fast                ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define scan(any)           for(auto &i:any) cin>>i;
#define print(any)          for(auto &i:any) cout<<i<<" "; nl;
#define printp(any)         for(auto &i:any) cout<<i.ff<<" "<<i.ss<<endl;
#define precise(a)          cout<<fixed<<setprecision(a)
inline  void yes()          {std::cout<<"Yes\n";}
inline  void no()           {std::cout<<"No\n";}
#define flush               std::cout.flush()
#define nl                  std::cout<<'\n'
#define endl                '\n'

// Template -----------------------------------------------------------------

template <typename T>
inline bool inrange(T a, T l, T r) {
    if(l>r) swap(l,r);
    return (a>=l and a<=r);
}
template <typename T, typename U>
inline bool exist(T val, U &any) {
    return (any.find(val) != any.end());
}
// multiple input
template <typename T>
inline void inp(T &any) {
    cin >> any;
}
template <typename T, typename... U>
inline void inp(T &a,U &...b) {
    cin >> a; inp(b...);
}
// scan vector
template <typename T>
inline istream& operator >> (istream &in, vector<T> &a) {
    for(auto &x : a) in >> x;
    return in;
}
// scan pair
template <typename T, typename U>
inline istream& operator >> (istream &in, pair<T,U> &a) {
    in >> a.ff >> a.ss;
    return in;
}

// Solve --------------------------------------------------------------------

using graph = vector<vector<ll>>;
void solve(ll &T)
{
    ll n, m;
    std::cin>>n>>m;

    set<ll> s;
    graph g(n);
    loop(i,0,m)
    {
        ll x, y;
        std::cin>>x>>y;
        x--, y--;
        g[x].eb(y);
        s.emplace(x);
        s.emplace(y);
    }

    set<ll> s1, s2;
    loop(i,0,n)
    {
        for(auto adj : g[i])
        {
            ll x = i + 1;
            ll y = adj + 1;

            if((exist(x,s1) and exist(y,s1)) or (exist(x,s2) and exist(y,s2)))
            {
                std::cout<<-1;
                return;
            }
            else if(exist(x,s1)) s2.emplace(y);
            else if(exist(y,s1)) s2.emplace(x);
            else if(exist(y,s2)) s1.emplace(x);
            else if(exist(x,s2)) s1.emplace(y);
            else
            {
                s1.emplace(x);
                s2.emplace(y);
            }
        }
    }

    if(s1.size()+s2.size()!=s.size())
    {
        std::cout<<-1;
        return;
    }

    std::cout<<s1.size(); nl;
    print(s1);

    std::cout<<s2.size(); nl;
    print(s2);
}

// Main ---------------------------------------------------------------------

int main()
{
    #ifdef Dhiraj
        freopen("D:/dhiraj/Programming/i1.txt","r",stdin);
        freopen("D:/dhiraj/Programming/o1.txt","w",stdout);
    #endif

    fast;
    int t = 1;
    loop(i,1,t+1)
    solve(i);
    return 0;
}


#if __has_include("D:/dhiraj/Programming/debug.h") && __has_include(<stdint.h>)
    #include "D:/dhiraj/Programming/debug.h"
#else
    #include <bits/stdc++.h>
    using namespace std;
    #define d(...) 11
#endif

// Data Type ----------------------------------------------------------------

#define ull                 unsigned long long int
#define ll                  long long int
#define ld                  long double

// Loops --------------------------------------------------------------------

#define loop(i,s,e)         for(ll i=(s); i<(e); i++)
#define rloop(i,s,e)        for(ll i=(s); i>=(e); i--)
#define iter(it,var)        for(auto it=var.begin(); it!=var.end(); it++)
#define riter(it,var)       for(auto it=var.rbegin(); it!=var.rend(); it++)

// Stl ----------------------------------------------------------------------

#define pb                  push_back
#define pf                  push_front
#define eb                  emplace_back
#define popb                pop_back
#define popf                pop_front
#define mp                  make_pair
#define mt                  make_tuple
#define ff                  first
#define ss                  second
#define vll                 vector<ll>
#define vvl                 vector<vll>
#define pll                 pair<ll,ll>
#define ub                  upper_bound
#define lb                  lower_bound
#define bs                  binary_search
#define all(x)              x.begin(),x.end()
#define allb(x)             x.begin(),x.begin()
#define rall(x)             x.rbegin(),x.rend()
#define at(ind,tup)         get<ind>(tup)
#define make_unique(x)      sort(all(x)); x.erase(unique(all(x)),x.end())

// Maths --------------------------------------------------------------------

const double PI = 2*acos(0.0);
#define gcd(a,b)            __gcd((a),(b))
#define lcm(a,b)            ((a)/(__gcd((a),(b)))*(b))
#define Log(x,b)            (log(x)/log(b))
#define iNF                 INT_MAX
#define INF                 LLONG_MAX

// Big data -----------------------------------------------------------------

const int Mod = 1E9 + 7;
#define Mul(a,b)            (((a) % Mod)*((b) % Mod)) % Mod
#define Sum(a,b)            (((a) % Mod)+((b) % Mod)) % Mod
#define Sub(a,b)            (((a) % Mod)-((b) % Mod) + Mod) % Mod
#define Div(a,b)            Mul(a,modInverse(b))

// Bit-Manipulation ---------------------------------------------------------

#define Bit(n)              bitset<n>
#define setbit(pos,n)       n |= (1LL<<pos)
#define resetbit(pos,n)     n &= (~(1LL<<pos))
#define toogle(pos,n)       n ^= (1LL<<pos)
#define atpos(pos,n)        ((n&(1LL<<pos))!=0)
#define bits(n)             (floor(log2(n)) + 1)
#define rightone(n)         (__builtin_ffs(n)-1)
#define countone(n)         (__builtin_popcountll(n))
#define parity(n)           (__builtin_parity(n))
#define counttz(n)          (__builtin_ctzll(n))
#define countlz(n)          (__builtin_clzll(n))

// Extra --------------------------------------------------------------------

#define fast                ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define scan(any)           for(auto &i:any) cin>>i;
#define print(any)          for(auto &i:any) cout<<i<<" "; nl;
#define printp(any)         for(auto &i:any) cout<<i.ff<<" "<<i.ss<<endl;
#define precise(a)          cout<<fixed<<setprecision(a)
inline  void yes()          {std::cout<<"Yes\n";}
inline  void no()           {std::cout<<"No\n";}
#define flush               std::cout.flush()
#define nl                  std::cout<<'\n'
#define endl                '\n'

// Template -----------------------------------------------------------------

template <typename T>
inline bool inrange(T a, T l, T r) {
    if(l>r) swap(l,r);
    return (a>=l and a<=r);
}
template <typename T, typename U>
inline bool exist(T val, U &any) {
    return (any.find(val) != any.end());
}
// multiple input
template <typename T>
inline void inp(T &any) {
    cin >> any;
}
template <typename T, typename... U>
inline void inp(T &a,U &...b) {
    cin >> a; inp(b...);
}
// scan vector
template <typename T>
inline istream& operator >> (istream &in, vector<T> &a) {
    for(auto &x : a) in >> x;
    return in;
}
// scan pair
template <typename T, typename U>
inline istream& operator >> (istream &in, pair<T,U> &a) {
    in >> a.ff >> a.ss;
    return in;
}

// Solve --------------------------------------------------------------------

using graph = vector<vector<ll>>;
void solve(ll &T)
{
    ll n, m;
    std::cin>>n>>m;

    graph g(n);
    loop(i,0,m)
    {
        ll x, y;
        std::cin>>x>>y;
        x--, y--;
        g[x].eb(y);
        g[y].eb(x);
    }

    vll ans[2];
    vector<bool> visited(n);

    loop(i,0,n)
    {
        if(!visited[i])
        {
            visited[i] = true;
            queue<ll> q;
            q.push(i);
            ans[1].eb(i+1);

            vll clr(n,-1);
            clr[i] = 1;

            while(!q.empty())
            {
                ll next = q.front(); q.pop();
                for(ll &adj : g[next])
                {
                    if(!visited[adj])
                    {
                        visited[adj] = true;
                        clr[adj] = clr[next] ? 0 : 1;
                        ans[clr[adj]].eb(adj+1);
                        q.push(adj);
                    }
                    else if(clr[adj]!=-1 and clr[adj]==clr[next])
                    {
                        std::cout<<-1<<endl;
                        return;
                    }
                }
            }
        }
    }

    std::cout<<ans[0].size()<<endl;
    print(ans[0]);

    std::cout<<ans[1].size()<<endl;
    print(ans[1]);
}

// Main ---------------------------------------------------------------------

int main()
{
    #ifdef Dhiraj
        freopen("D:/dhiraj/Programming/i1.txt","r",stdin);
        freopen("D:/dhiraj/Programming/o1.txt","w",stdout);
    #endif

    fast;
    int t = 1;
    loop(i,1,t+1)
    solve(i);
    return 0;
}


#if __has_include("D:/dhiraj/Programming/debug.h") && __has_include(<stdint.h>)
    #include "D:/dhiraj/Programming/debug.h"
#else
    #include <bits/stdc++.h>
    using namespace std;
    #define d(...) 11
#endif

// Data Type ----------------------------------------------------------------

#define ull                 unsigned long long int
#define ll                  long long int
#define ld                  long double

// Loops --------------------------------------------------------------------

#define loop(i,s,e)         for(ll i=(s); i<(e); i++)
#define rloop(i,s,e)        for(ll i=(s); i>=(e); i--)
#define iter(it,var)        for(auto it=var.begin(); it!=var.end(); it++)
#define riter(it,var)       for(auto it=var.rbegin(); it!=var.rend(); it++)

// Stl ----------------------------------------------------------------------

#define pb                  push_back
#define pf                  push_front
#define eb                  emplace_back
#define popb                pop_back
#define popf                pop_front
#define mp                  make_pair
#define mt                  make_tuple
#define ff                  first
#define ss                  second
#define vll                 vector<ll>
#define vvl                 vector<vll>
#define pll                 pair<ll,ll>
#define ub                  upper_bound
#define lb                  lower_bound
#define bs                  binary_search
#define all(x)              x.begin(),x.end()
#define allb(x)             x.begin(),x.begin()
#define rall(x)             x.rbegin(),x.rend()
#define at(ind,tup)         get<ind>(tup)
#define make_unique(x)      sort(all(x)); x.erase(unique(all(x)),x.end())

// Maths --------------------------------------------------------------------

const double PI = 2*acos(0.0);
#define gcd(a,b)            __gcd((a),(b))
#define lcm(a,b)            ((a)/(__gcd((a),(b)))*(b))
#define Log(x,b)            (log(x)/log(b))
#define iNF                 INT_MAX
#define INF                 LLONG_MAX

// Big data -----------------------------------------------------------------

const int Mod = 1E9 + 7;
#define Mul(a,b)            (((a) % Mod)*((b) % Mod)) % Mod
#define Sum(a,b)            (((a) % Mod)+((b) % Mod)) % Mod
#define Sub(a,b)            (((a) % Mod)-((b) % Mod) + Mod) % Mod
#define Div(a,b)            Mul(a,modInverse(b))

// Bit-Manipulation ---------------------------------------------------------

#define Bit(n)              bitset<n>
#define setbit(pos,n)       n |= (1LL<<pos)
#define resetbit(pos,n)     n &= (~(1LL<<pos))
#define toogle(pos,n)       n ^= (1LL<<pos)
#define atpos(pos,n)        ((n&(1LL<<pos))!=0)
#define bits(n)             (floor(log2(n)) + 1)
#define rightone(n)         (__builtin_ffs(n)-1)
#define countone(n)         (__builtin_popcountll(n))
#define parity(n)           (__builtin_parity(n))
#define counttz(n)          (__builtin_ctzll(n))
#define countlz(n)          (__builtin_clzll(n))

// Extra --------------------------------------------------------------------

#define fast                ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define scan(any)           for(auto &i:any) cin>>i;
#define print(any)          for(auto &i:any) cout<<i<<" "; nl;
#define printp(any)         for(auto &i:any) cout<<i.ff<<" "<<i.ss<<endl;
#define precise(a)          cout<<fixed<<setprecision(a)
inline  void yes()          {std::cout<<"Yes\n";}
inline  void no()           {std::cout<<"No\n";}
#define flush               std::cout.flush()
#define nl                  std::cout<<'\n'
#define endl                '\n'

// Template -----------------------------------------------------------------

template <typename T>
inline bool inrange(T a, T l, T r) {
    if(l>r) swap(l,r);
    return (a>=l and a<=r);
}
template <typename T, typename U>
inline bool exist(T val, U &any) {
    return (any.find(val) != any.end());
}
// multiple input
template <typename T>
inline void inp(T &any) {
    cin >> any;
}
template <typename T, typename... U>
inline void inp(T &a,U &...b) {
    cin >> a; inp(b...);
}
// scan vector
template <typename T>
inline istream& operator >> (istream &in, vector<T> &a) {
    for(auto &x : a) in >> x;
    return in;
}
// scan pair
template <typename T, typename U>
inline istream& operator >> (istream &in, pair<T,U> &a) {
    in >> a.ff >> a.ss;
    return in;
}

// Solve --------------------------------------------------------------------

using graph = vector<vector<ll>>;
void solve(ll &T)
{
    ll n, m;
    std::cin>>n>>m;

    graph g(n);
    loop(i,0,m)
    {
        ll x, y;
        std::cin>>x>>y;
        x--, y--;
        g[x].eb(y);
        g[y].eb(x);
    }

    vll clr(n,-1);
    clr[0] = 1;

    vll ans[2];
    vector<bool> visited(n);
    visited[0] = true;

    queue<ll> q;
    q.push(0);
    ans[1].eb(1);

    while(!q.empty())
    {
        ll next = q.front(); q.pop();
        for(ll &adj : g[next])
        {
            if(!visited[adj])
            {
                visited[adj] = true;
                clr[adj] = clr[next] ? 0 : 1;
                ans[clr[adj]].eb(adj+1);
                q.push(adj);
            }
            else if(clr[adj]==clr[next])
            {
                std::cout<<-1<<endl;
                return;
            }
        }
    }

    std::cout<<ans[0].size()<<endl;
    print(ans[0]);

    std::cout<<ans[1].size()<<endl;
    print(ans[1]);
}

// Main ---------------------------------------------------------------------

int main()
{
    #ifdef Dhiraj
        freopen("D:/dhiraj/Programming/i1.txt","r",stdin);
        freopen("D:/dhiraj/Programming/o1.txt","w",stdout);
    #endif

    fast;
    int t = 1;
    loop(i,1,t+1)
    solve(i);
    return 0;
}


/****************************************************************************

	" Be the change that you wish to see in the world. "
	-- Mahatma Gandhi

******************************************************************************
*                                                                            *
*                       Author : Dhiraj Govindvira                           *
*                         Date : 27-Mar-2020 ~ Friday                        *
*                         Time : 11:02:44 AM                                 *
*                                                                            *
*****************************************************************************/

#if __has_include("D:/dhiraj/Programming/debug.h") && __has_include(<stdint.h>)
    #include "D:/dhiraj/Programming/debug.h"
#else
    #include <bits/stdc++.h>
    using namespace std;
    #define d(...) 11
#endif

// Data Type ----------------------------------------------------------------

#define ull                 unsigned long long int
#define ll                  long long int
#define ld                  long double

// Loops --------------------------------------------------------------------

#define loop(i,s,e)         for(ll i=(s); i<(e); i++)
#define rloop(i,s,e)        for(ll i=(s); i>=(e); i--)
#define iter(it,var)        for(auto it=var.begin(); it!=var.end(); it++)
#define riter(it,var)       for(auto it=var.rbegin(); it!=var.rend(); it++)

// Stl ----------------------------------------------------------------------

#define pb                  push_back
#define pf                  push_front
#define eb                  emplace_back
#define popb                pop_back
#define popf                pop_front
#define mp                  make_pair
#define mt                  make_tuple
#define ff                  first
#define ss                  second
#define vll                 vector<ll>
#define vvl                 vector<vll>
#define pll                 pair<ll,ll>
#define ub                  upper_bound
#define lb                  lower_bound
#define bs                  binary_search
#define all(x)              x.begin(),x.end()
#define allb(x)             x.begin(),x.begin()
#define rall(x)             x.rbegin(),x.rend()
#define at(ind,tup)         get<ind>(tup)
#define make_unique(x)      sort(all(x)); x.erase(unique(all(x)),x.end())

// Maths --------------------------------------------------------------------

const double PI = 2*acos(0.0);
#define gcd(a,b)            __gcd((a),(b))
#define lcm(a,b)            ((a)/(__gcd((a),(b)))*(b))
#define Log(x,b)            (log(x)/log(b))
#define iNF                 INT_MAX
#define INF                 LLONG_MAX

// Big data -----------------------------------------------------------------

const int Mod = 1E9 + 7;
#define Mul(a,b)            (((a) % Mod)*((b) % Mod)) % Mod
#define Sum(a,b)            (((a) % Mod)+((b) % Mod)) % Mod
#define Sub(a,b)            (((a) % Mod)-((b) % Mod) + Mod) % Mod
#define Div(a,b)            Mul(a,modInverse(b))

// Bit-Manipulation ---------------------------------------------------------

#define Bit(n)              bitset<n>
#define setbit(pos,n)       n |= (1LL<<pos)
#define resetbit(pos,n)     n &= (~(1LL<<pos))
#define toogle(pos,n)       n ^= (1LL<<pos)
#define atpos(pos,n)        ((n&(1LL<<pos))!=0)
#define bits(n)             (floor(log2(n)) + 1)
#define rightone(n)         (__builtin_ffs(n)-1)
#define countone(n)         (__builtin_popcountll(n))
#define parity(n)           (__builtin_parity(n))
#define counttz(n)          (__builtin_ctzll(n))
#define countlz(n)          (__builtin_clzll(n))

// Extra --------------------------------------------------------------------

#define fast                ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define scan(any)           for(auto &i:any) cin>>i;
#define print(any)          for(auto &i:any) cout<<i<<" "; nl;
#define printp(any)         for(auto &i:any) cout<<i.ff<<" "<<i.ss<<endl;
#define precise(a)          cout<<fixed<<setprecision(a)
inline  void yes()          {std::cout<<"Yes\n";}
inline  void no()           {std::cout<<"No\n";}
#define flush               std::cout.flush()
#define nl                  std::cout<<'\n'
#define endl                '\n'

// Template -----------------------------------------------------------------

template <typename T>
inline bool inrange(T a, T l, T r) {
    if(l>r) swap(l,r);
    return (a>=l and a<=r);
}
template <typename T, typename U>
inline bool exist(T val, U &any) {
    return (any.find(val) != any.end());
}
// multiple input
template <typename T>
inline void inp(T &any) {
    cin >> any;
}
template <typename T, typename... U>
inline void inp(T &a,U &...b) {
    cin >> a; inp(b...);
}
// scan vector
template <typename T>
inline istream& operator >> (istream &in, vector<T> &a) {
    for(auto &x : a) in >> x;
    return in;
}
// scan pair
template <typename T, typename U>
inline istream& operator >> (istream &in, pair<T,U> &a) {
    in >> a.ff >> a.ss;
    return in;
}

// Solve --------------------------------------------------------------------

using graph = vector<vector<ll>>;
void solve(ll &T)
{
    ll n, m;
    std::cin>>n>>m;

    set<ll> s;
    graph g(n);
    loop(i,0,m)
    {
        ll x, y;
        std::cin>>x>>y;
        x--, y--;
        g[x].eb(y);
        s.emplace(x);
        s.emplace(y);
    }

    set<ll> s1, s2;
    loop(i,0,n)
    {
        for(auto adj : g[i])
        {
            ll x = i + 1;
            ll y = adj + 1;

            if(exist(x,s1)) s2.emplace(y);
            else if(exist(y,s1)) s2.emplace(x);
            else if(exist(y,s2)) s1.emplace(x);
            else if(exist(x,s2)) s1.emplace(y);
            else
            {
                s1.emplace(x);
                s2.emplace(y);
            }
        }
    }

    if(s1.size()+s2.size()!=s.size())
    {
        std::cout<<-1;
        return;
    }

    std::cout<<s1.size(); nl;
    print(s1);

    std::cout<<s2.size(); nl;
    print(s2);
}

// Main ---------------------------------------------------------------------

int main()
{
    #ifdef Dhiraj
        freopen("D:/dhiraj/Programming/i1.txt","r",stdin);
        freopen("D:/dhiraj/Programming/o1.txt","w",stdout);
    #endif

    fast;
    int t = 1;
    loop(i,1,t+1)
    solve(i);
    return 0;
}


#if __has_include("D:/dhiraj/Programming/debug.h") && __has_include(<stdint.h>)
    #include "D:/dhiraj/Programming/debug.h"
#else
    #include <bits/stdc++.h>
    using namespace std;
    #define d(...) 11
#endif

// Data Type ----------------------------------------------------------------

#define ull                 unsigned long long int
#define ll                  long long int
#define ld                  long double

// Loops --------------------------------------------------------------------

#define loop(i,s,e)         for(ll i=(s); i<(e); i++)
#define rloop(i,s,e)        for(ll i=(s); i>=(e); i--)
#define iter(it,var)        for(auto it=var.begin(); it!=var.end(); it++)
#define riter(it,var)       for(auto it=var.rbegin(); it!=var.rend(); it++)

// Stl ----------------------------------------------------------------------

#define pb                  push_back
#define pf                  push_front
#define eb                  emplace_back
#define popb                pop_back
#define popf                pop_front
#define mp                  make_pair
#define mt                  make_tuple
#define ff                  first
#define ss                  second
#define vll                 vector<ll>
#define vvl                 vector<vll>
#define pll                 pair<ll,ll>
#define ub                  upper_bound
#define lb                  lower_bound
#define bs                  binary_search
#define all(x)              x.begin(),x.end()
#define allb(x)             x.begin(),x.begin()
#define rall(x)             x.rbegin(),x.rend()
#define at(ind,tup)         get<ind>(tup)
#define make_unique(x)      sort(all(x)); x.erase(unique(all(x)),x.end())

// Maths --------------------------------------------------------------------

const double PI = 2*acos(0.0);
#define gcd(a,b)            __gcd((a),(b))
#define lcm(a,b)            ((a)/(__gcd((a),(b)))*(b))
#define Log(x,b)            (log(x)/log(b))
#define iNF                 INT_MAX
#define INF                 LLONG_MAX

// Big data -----------------------------------------------------------------

const int Mod = 1E9 + 7;
#define Mul(a,b)            (((a) % Mod)*((b) % Mod)) % Mod
#define Sum(a,b)            (((a) % Mod)+((b) % Mod)) % Mod
#define Sub(a,b)            (((a) % Mod)-((b) % Mod) + Mod) % Mod
#define Div(a,b)            Mul(a,modInverse(b))

// Bit-Manipulation ---------------------------------------------------------

#define Bit(n)              bitset<n>
#define setbit(pos,n)       n |= (1LL<<pos)
#define resetbit(pos,n)     n &= (~(1LL<<pos))
#define toogle(pos,n)       n ^= (1LL<<pos)
#define atpos(pos,n)        ((n&(1LL<<pos))!=0)
#define bits(n)             (floor(log2(n)) + 1)
#define rightone(n)         (__builtin_ffs(n)-1)
#define countone(n)         (__builtin_popcountll(n))
#define parity(n)           (__builtin_parity(n))
#define counttz(n)          (__builtin_ctzll(n))
#define countlz(n)          (__builtin_clzll(n))

// Extra --------------------------------------------------------------------

#define fast                ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define scan(any)           for(auto &i:any) cin>>i;
#define print(any)          for(auto &i:any) cout<<i<<" "; nl;
#define printp(any)         for(auto &i:any) cout<<i.ff<<" "<<i.ss<<endl;
#define precise(a)          cout<<fixed<<setprecision(a)
inline  void yes()          {std::cout<<"Yes\n";}
inline  void no()           {std::cout<<"No\n";}
#define flush               std::cout.flush()
#define nl                  std::cout<<'\n'
#define endl                '\n'

// Template -----------------------------------------------------------------

template <typename T>
inline bool inrange(T a, T l, T r) {
    if(l>r) swap(l,r);
    return (a>=l and a<=r);
}
template <typename T, typename U>
inline bool exist(T val, U &any) {
    return (any.find(val) != any.end());
}
// multiple input
template <typename T>
inline void inp(T &any) {
    cin >> any;
}
template <typename T, typename... U>
inline void inp(T &a,U &...b) {
    cin >> a; inp(b...);
}
// scan vector
template <typename T>
inline istream& operator >> (istream &in, vector<T> &a) {
    for(auto &x : a) in >> x;
    return in;
}
// scan pair
template <typename T, typename U>
inline istream& operator >> (istream &in, pair<T,U> &a) {
    in >> a.ff >> a.ss;
    return in;
}

// Solve --------------------------------------------------------------------

using graph = vector<vector<ll>>;
void solve(ll &T)
{
    ll n, m;
    std::cin>>n>>m;

    graph g(n);
    loop(i,0,m)
    {
        ll x, y;
        std::cin>>x>>y;
        x--, y--;
        g[x].eb(y);
        g[y].eb(x);
    }

    vll ans[2];
    vll clr(n,-1);
    vector<bool> visited(n);

    loop(i,0,n)
    {
        if(!visited[i])
        {
            visited[i] = true;
            clr[i] = 1;
            ans[1].eb(i+1);

            queue<ll> q;
            q.push(i);
            while(!q.empty())
            {
                ll next = q.front(); q.pop();
                for(ll &adj : g[next])
                {
                    if(!visited[adj])
                    {
                        visited[adj] = true;
                        clr[adj] = clr[next] ? 0 : 1;
                        ans[clr[adj]].eb(adj+1);
                        q.push(adj);
                    }
                    else if(clr[adj]==clr[next])
                    {
                        std::cout<<-1<<endl;
                        return;
                    }
                }
            }
        }
    }

    std::cout<<ans[0].size()<<endl;
    print(ans[0]);

    std::cout<<ans[1].size()<<endl;
    print(ans[1]);
}

// Main ---------------------------------------------------------------------

int main()
{
    #ifdef Dhiraj
        freopen("D:/dhiraj/Programming/i1.txt","r",stdin);
        freopen("D:/dhiraj/Programming/o1.txt","w",stdout);
    #endif

    fast;
    int t = 1;
    loop(i,1,t+1)
    solve(i);
    return 0;
}


#if __has_include("D:/dhiraj/Programming/debug.h") && __has_include(<stdint.h>)
    #include "D:/dhiraj/Programming/debug.h"
#else
    #include <bits/stdc++.h>
    using namespace std;
    #define d(...) 11
#endif

// Data Type ----------------------------------------------------------------

#define ull                 unsigned long long int
#define ll                  long long int
#define ld                  long double

// Loops --------------------------------------------------------------------

#define loop(i,s,e)         for(ll i=(s); i<(e); i++)
#define rloop(i,s,e)        for(ll i=(s); i>=(e); i--)
#define iter(it,var)        for(auto it=var.begin(); it!=var.end(); it++)
#define riter(it,var)       for(auto it=var.rbegin(); it!=var.rend(); it++)

// Stl ----------------------------------------------------------------------

#define pb                  push_back
#define pf                  push_front
#define eb                  emplace_back
#define popb                pop_back
#define popf                pop_front
#define mp                  make_pair
#define mt                  make_tuple
#define ff                  first
#define ss                  second
#define vll                 vector<ll>
#define vvl                 vector<vll>
#define pll                 pair<ll,ll>
#define ub                  upper_bound
#define lb                  lower_bound
#define bs                  binary_search
#define all(x)              x.begin(),x.end()
#define allb(x)             x.begin(),x.begin()
#define rall(x)             x.rbegin(),x.rend()
#define at(ind,tup)         get<ind>(tup)
#define make_unique(x)      sort(all(x)); x.erase(unique(all(x)),x.end())

// Maths --------------------------------------------------------------------

const double PI = 2*acos(0.0);
#define gcd(a,b)            __gcd((a),(b))
#define lcm(a,b)            ((a)/(__gcd((a),(b)))*(b))
#define Log(x,b)            (log(x)/log(b))
#define iNF                 INT_MAX
#define INF                 LLONG_MAX

// Big data -----------------------------------------------------------------

const int Mod = 1E9 + 7;
#define Mul(a,b)            (((a) % Mod)*((b) % Mod)) % Mod
#define Sum(a,b)            (((a) % Mod)+((b) % Mod)) % Mod
#define Sub(a,b)            (((a) % Mod)-((b) % Mod) + Mod) % Mod
#define Div(a,b)            Mul(a,modInverse(b))

// Bit-Manipulation ---------------------------------------------------------

#define Bit(n)              bitset<n>
#define setbit(pos,n)       n |= (1LL<<pos)
#define resetbit(pos,n)     n &= (~(1LL<<pos))
#define toogle(pos,n)       n ^= (1LL<<pos)
#define atpos(pos,n)        ((n&(1LL<<pos))!=0)
#define bits(n)             (floor(log2(n)) + 1)
#define rightone(n)         (__builtin_ffs(n)-1)
#define countone(n)         (__builtin_popcountll(n))
#define parity(n)           (__builtin_parity(n))
#define counttz(n)          (__builtin_ctzll(n))
#define countlz(n)          (__builtin_clzll(n))

// Extra --------------------------------------------------------------------

#define fast                ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define scan(any)           for(auto &i:any) cin>>i;
#define print(any)          for(auto &i:any) cout<<i<<" "; nl;
#define printp(any)         for(auto &i:any) cout<<i.ff<<" "<<i.ss<<endl;
#define precise(a)          cout<<fixed<<setprecision(a)
inline  void yes()          {std::cout<<"Yes\n";}
inline  void no()           {std::cout<<"No\n";}
#define flush               std::cout.flush()
#define nl                  std::cout<<'\n'
#define endl                '\n'

// Template -----------------------------------------------------------------

template <typename T>
inline bool inrange(T a, T l, T r) {
    if(l>r) swap(l,r);
    return (a>=l and a<=r);
}
template <typename T, typename U>
inline bool exist(T val, U &any) {
    return (any.find(val) != any.end());
}
// multiple input
template <typename T>
inline void inp(T &any) {
    cin >> any;
}
template <typename T, typename... U>
inline void inp(T &a,U &...b) {
    cin >> a; inp(b...);
}
// scan vector
template <typename T>
inline istream& operator >> (istream &in, vector<T> &a) {
    for(auto &x : a) in >> x;
    return in;
}
// scan pair
template <typename T, typename U>
inline istream& operator >> (istream &in, pair<T,U> &a) {
    in >> a.ff >> a.ss;
    return in;
}

// Solve --------------------------------------------------------------------

using graph = vector<vector<ll>>;
void solve(ll &T)
{
    ll n, m;
    std::cin>>n>>m;

    graph g(n);
    loop(i,0,m)
    {
        ll x, y;
        std::cin>>x>>y;
        x--, y--;
        g[x].eb(y);
        g[y].eb(x);
    }

    vll clr(n,-1);
    clr[0] = 1;

    vll ans[2];
    vector<bool> visited(n);
    visited[0] = true;

    queue<ll> q;
    q.push(0);
    ans[1].eb(1);

    while(!q.empty())
    {
        ll next = q.front(); q.pop();
        for(ll &adj : g[next])
        {
            if(!visited[adj])
            {
                visited[adj] = true;
                clr[adj] = clr[next] ? 0 : 1;
                ans[clr[adj]].eb(adj+1);
                q.push(adj);
            }
            else if(clr[adj]!=-1 and clr[adj]==clr[next])
            {
                std::cout<<-1<<endl;
                return;
            }
        }
    }

    std::cout<<ans[0].size()<<endl;
    print(ans[0]);

    std::cout<<ans[1].size()<<endl;
    print(ans[1]);
}

// Main ---------------------------------------------------------------------

int main()
{
    #ifdef Dhiraj
        freopen("D:/dhiraj/Programming/i1.txt","r",stdin);
        freopen("D:/dhiraj/Programming/o1.txt","w",stdout);
    #endif

    fast;
    int t = 1;
    loop(i,1,t+1)
    solve(i);
    return 0;
}


#if __has_include("D:/dhiraj/Programming/debug.h") && __has_include(<stdint.h>)
    #include "D:/dhiraj/Programming/debug.h"
#else
    #include <bits/stdc++.h>
    using namespace std;
    #define d(...) 11
#endif

// Data Type ----------------------------------------------------------------

#define ull                 unsigned long long int
#define ll                  long long int
#define ld                  long double

// Loops --------------------------------------------------------------------

#define loop(i,s,e)         for(ll i=(s); i<(e); i++)
#define rloop(i,s,e)        for(ll i=(s); i>=(e); i--)
#define iter(it,var)        for(auto it=var.begin(); it!=var.end(); it++)
#define riter(it,var)       for(auto it=var.rbegin(); it!=var.rend(); it++)

// Stl ----------------------------------------------------------------------

#define pb                  push_back
#define pf                  push_front
#define eb                  emplace_back
#define popb                pop_back
#define popf                pop_front
#define mp                  make_pair
#define mt                  make_tuple
#define ff                  first
#define ss                  second
#define vll                 vector<ll>
#define vvl                 vector<vll>
#define pll                 pair<ll,ll>
#define ub                  upper_bound
#define lb                  lower_bound
#define bs                  binary_search
#define all(x)              x.begin(),x.end()
#define allb(x)             x.begin(),x.begin()
#define rall(x)             x.rbegin(),x.rend()
#define at(ind,tup)         get<ind>(tup)
#define make_unique(x)      sort(all(x)); x.erase(unique(all(x)),x.end())

// Maths --------------------------------------------------------------------

const double PI = 2*acos(0.0);
#define gcd(a,b)            __gcd((a),(b))
#define lcm(a,b)            ((a)/(__gcd((a),(b)))*(b))
#define Log(x,b)            (log(x)/log(b))
#define iNF                 INT_MAX
#define INF                 LLONG_MAX

// Big data -----------------------------------------------------------------

const int Mod = 1E9 + 7;
#define Mul(a,b)            (((a) % Mod)*((b) % Mod)) % Mod
#define Sum(a,b)            (((a) % Mod)+((b) % Mod)) % Mod
#define Sub(a,b)            (((a) % Mod)-((b) % Mod) + Mod) % Mod
#define Div(a,b)            Mul(a,modInverse(b))

// Bit-Manipulation ---------------------------------------------------------

#define Bit(n)              bitset<n>
#define setbit(pos,n)       n |= (1LL<<pos)
#define resetbit(pos,n)     n &= (~(1LL<<pos))
#define toogle(pos,n)       n ^= (1LL<<pos)
#define atpos(pos,n)        ((n&(1LL<<pos))!=0)
#define bits(n)             (floor(log2(n)) + 1)
#define rightone(n)         (__builtin_ffs(n)-1)
#define countone(n)         (__builtin_popcountll(n))
#define parity(n)           (__builtin_parity(n))
#define counttz(n)          (__builtin_ctzll(n))
#define countlz(n)          (__builtin_clzll(n))

// Extra --------------------------------------------------------------------

#define fast                ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define scan(any)           for(auto &i:any) cin>>i;
#define print(any)          for(auto &i:any) cout<<i<<" "; nl;
#define printp(any)         for(auto &i:any) cout<<i.ff<<" "<<i.ss<<endl;
#define precise(a)          cout<<fixed<<setprecision(a)
inline  void yes()          {std::cout<<"Yes\n";}
inline  void no()           {std::cout<<"No\n";}
#define flush               std::cout.flush()
#define nl                  std::cout<<'\n'
#define endl                '\n'

// Template -----------------------------------------------------------------

template <typename T>
inline bool inrange(T a, T l, T r) {
    if(l>r) swap(l,r);
    return (a>=l and a<=r);
}
template <typename T, typename U>
inline bool exist(T val, U &any) {
    return (any.find(val) != any.end());
}
// multiple input
template <typename T>
inline void inp(T &any) {
    cin >> any;
}
template <typename T, typename... U>
inline void inp(T &a,U &...b) {
    cin >> a; inp(b...);
}
// scan vector
template <typename T>
inline istream& operator >> (istream &in, vector<T> &a) {
    for(auto &x : a) in >> x;
    return in;
}
// scan pair
template <typename T, typename U>
inline istream& operator >> (istream &in, pair<T,U> &a) {
    in >> a.ff >> a.ss;
    return in;
}

// Solve --------------------------------------------------------------------

using graph = vector<vector<ll>>;
void solve(ll &T)
{
    ll n, m;
    std::cin>>n>>m;

    graph g(n);
    loop(i,0,m)
    {
        ll x, y;
        std::cin>>x>>y;
        x--, y--;
        g[x].eb(y);
        g[y].eb(x);
    }

    vll clr(n);
    clr[0] = 1;

    vll ans[2];
    vector<bool> visited(n);
    visited[0] = true;

    queue<ll> q;
    q.push(0);
    ans[0].eb(1);

    while(!q.empty())
    {
        ll next = q.front(); q.pop();
        for(ll &adj : g[next])
        {
            if(!visited[adj])
            {
                visited[adj] = true;
                clr[adj] = clr[next] ? 0 : 1;
                ans[clr[adj]].eb(adj+1);
                q.push(adj);
            }
            else if(clr[adj]==clr[next])
            {
                std::cout<<-1<<endl;
                return;
            }
        }
    }

    std::cout<<ans[0].size()<<endl;
    print(ans[0]);

    std::cout<<ans[1].size()<<endl;
    print(ans[1]);
}

// Main ---------------------------------------------------------------------

int main()
{
    #ifdef Dhiraj
        freopen("D:/dhiraj/Programming/i1.txt","r",stdin);
        freopen("D:/dhiraj/Programming/o1.txt","w",stdout);
    #endif

    fast;
    int t = 1;
    loop(i,1,t+1)
    solve(i);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

bool custom(pair<int64_t, vector<int64_t> > a, pair<int64_t, vector<int64_t> > b){
    // if(a.second.size()==b.second.size())
    //     return a.first > b.first;
    return a.second.size() > b.second.size();
}

bool customS1(pair<int, int> a, pair<int, int> b){
    // if(a.second==b.second)
    //     return a.first > b.first;
    return a.second < b.second;
}

bool customS2(pair<int, int> a, pair<int, int> b){
    if((a.first+a.second)==(b.first+b.second))
        return a.second < b.second;
    return (a.first+a.second)<(b.first+b.second);
}

class CompareDist
{
public:
    bool operator()(pair<int64_t, int64_t> a, pair<int64_t, int64_t> b){
        return a.first < b.first;
    }
};

int64_t gcd(int64_t a, int64_t b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

double gcdfloat(double a, double b) {
    if (a < b)
        return gcd(b, a);

    if (fabs(b) < 0.001)
        return a;

    else
        return (gcd(b, a - floor(a / b) * b));
}

// vector<int64_t> colors(200001, -1);
// // queue<int> q;

// void DFS(int64_t start, int64_t c1, int64_t c2){
//     // cout<<start<<" ";
//     colors[start] = c2;
//     visited[start] = 1;
//     // *ctr = *ctr + 1;
//     // cout<<start<<" "<<*ctr<<"\n";
//     // int t = nodes[start].size();
//     // *max_degree = max(*max_degree, t);
//     // bool temp=false;
//     // cout<<start<<" "<<initial[start]<<" "<<after[start]<<"\n";
//     int64_t color_ctr=1;
//     for(int i=0;i<nodes[start].size();i++){
//         if(visited[nodes[start][i]]==0){
//             while(color_ctr==c1 || color_ctr==c2)
//                 color_ctr++;

//             DFS(nodes[start][i], c2, color_ctr);
//             color_ctr += 1;

//         }
//     }
// }

int64_t LCA(int64_t a, int64_t b){
    while(a!=b){
        // cout<<a<<" "<<b<<"\n";
        if(b>a){
            swap(a, b);
        }
        a /= 2;
    }
    return a;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m, a, b, i, j;
    cin>>n>>m;
    vector<vector<int> > nodes(n+1);
    for(i=0;i<m;i++){
        cin>>a>>b;
        nodes[a].push_back(b);
        nodes[b].push_back(a);
    }
    // cout<<"done;";
    vector<int> partition(n+1, -1); // visited(n+1, 0),
    for(i=1;i<n+1;i++){
        if(partition[i]==-1){
            queue<int> q;
            q.push(i);
            q.push(-1);
            // visited[i] = 1;
            partition[i] = 0;
            int flag = 1;
            while(!q.empty()){
                int temp = q.front();
                q.pop();
                if(temp==-1){
                    if(!q.empty())
                        q.push(-1);
                    flag = flag ^ 1;
                    continue;
                }
                // cout<<"f "<<flag<<" "<<temp<<"\n";
                for(j=0;j<nodes[temp].size();j++){
                    // cout<<"p "<<nodes[temp][j]<<" "<<partition[nodes[temp][j]]<<"\n";
                    if(partition[nodes[temp][j]]==-1){
                        partition[nodes[temp][j]] = flag;
                        q.push(nodes[temp][j]);
                    }
                    else if(partition[nodes[temp][j]]==partition[temp]){
                        cout<<"-1\n";
                        return 0;
                    }
                }
            }
        }
        break;
    }
    vector<int> nodes_1, nodes_2;
    for(i=1;i<=n;i++){
        if(partition[i]==0)
            nodes_1.push_back(i);
        else if(partition[i]==1)
            nodes_2.push_back(i);
    }
    cout<<nodes_1.size()<<"\n";
    for(i=0;i<nodes_1.size();i++)
        cout<<nodes_1[i]<<" ";
    cout<<"\n";
    cout<<nodes_2.size()<<"\n";
    for(i=0;i<nodes_2.size();i++)
        cout<<nodes_2[i]<<" ";
    cout<<"\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

bool custom(pair<int64_t, vector<int64_t> > a, pair<int64_t, vector<int64_t> > b){
    // if(a.second.size()==b.second.size())
    //     return a.first > b.first;
    return a.second.size() > b.second.size();
}

bool customS1(pair<int, int> a, pair<int, int> b){
    // if(a.second==b.second)
    //     return a.first > b.first;
    return a.second < b.second;
}

bool customS2(pair<int, int> a, pair<int, int> b){
    if((a.first+a.second)==(b.first+b.second))
        return a.second < b.second;
    return (a.first+a.second)<(b.first+b.second);
}

class CompareDist
{
public:
    bool operator()(pair<int64_t, int64_t> a, pair<int64_t, int64_t> b){
        return a.first < b.first;
    }
};

int64_t gcd(int64_t a, int64_t b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

double gcdfloat(double a, double b) {
    if (a < b)
        return gcd(b, a);

    if (fabs(b) < 0.001)
        return a;

    else
        return (gcd(b, a - floor(a / b) * b));
}

vector<vector<int> >nodes(100001);
vector<int64_t> partitions(100001, -1);
// // queue<int> q;

void DFS(int64_t start, int64_t color, bool *ans){
    // cout<<"c "<<start<<" "<<color<<"\n";
    partitions[start] = color;
    // visited[start] = 1;
    // *ctr = *ctr + 1;
    // cout<<start<<" "<<*ctr<<"\n";
    // int t = nodes[start].size();
    // *max_degree = max(*max_degree, t);
    // bool temp=false;
    // cout<<start<<" "<<initial[start]<<" "<<after[start]<<"\n";
    int flag;
    if(color==0)
        flag = 1;
    else
        flag = 0;
    int64_t color_ctr=1;
    for(int i=0;i<nodes[start].size();i++){
        // cout<<start<<" "<<nodes[start][i]<<" "<<partitions[start]<<" "<<partitions[nodes[start][i]]<<"\n";
        if(partitions[nodes[start][i]]==-1){
            DFS(nodes[start][i], flag, ans);
        }
        else if(partitions[start]==partitions[nodes[start][i]]){
            *ans = false;
            // cout<<"answer is false\n";
        }
    }
    *ans = *ans & true;
}

int64_t LCA(int64_t a, int64_t b){
    while(a!=b){
        // cout<<a<<" "<<b<<"\n";
        if(b>a){
            swap(a, b);
        }
        a /= 2;
    }
    return a;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m, a, b, i, j;
    cin>>n>>m;
    for(i=0;i<m;i++){
        cin>>a>>b;
        nodes[a].push_back(b);
        nodes[b].push_back(a);
    }
    // cout<<"done;";
    bool ans = true;
    for(i=1;i<n+1;i++){
        if(partitions[i]==-1){
            DFS(i, 0, &ans);
        }
    }
    if(ans==false){
        cout<<-1<<"\n";
        return 0;
    }
    vector<int> nodes_1, nodes_2;
    for(i=1;i<=n;i++){
        if(partitions[i]==0)
            nodes_1.push_back(i);
        else if(partitions[i]==1)
            nodes_2.push_back(i);
    }
    cout<<nodes_1.size()<<"\n";
    for(i=0;i<nodes_1.size();i++)
        cout<<nodes_1[i]<<" ";
    cout<<"\n";
    cout<<nodes_2.size()<<"\n";
    for(i=0;i<nodes_2.size();i++)
        cout<<nodes_2[i]<<" ";
    cout<<"\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

bool custom(pair<int64_t, vector<int64_t> > a, pair<int64_t, vector<int64_t> > b){
    // if(a.second.size()==b.second.size())
    //     return a.first > b.first;
    return a.second.size() > b.second.size();
}

bool customS1(pair<int, int> a, pair<int, int> b){
    // if(a.second==b.second)
    //     return a.first > b.first;
    return a.second < b.second;
}

bool customS2(pair<int, int> a, pair<int, int> b){
    if((a.first+a.second)==(b.first+b.second))
        return a.second < b.second;
    return (a.first+a.second)<(b.first+b.second);
}

class CompareDist
{
public:
    bool operator()(pair<int64_t, int64_t> a, pair<int64_t, int64_t> b){
        return a.first < b.first;
    }
};

int64_t gcd(int64_t a, int64_t b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

double gcdfloat(double a, double b) {
    if (a < b)
        return gcd(b, a);

    if (fabs(b) < 0.001)
        return a;

    else
        return (gcd(b, a - floor(a / b) * b));
}

// vector<int64_t> colors(200001, -1);
// // queue<int> q;

// void DFS(int64_t start, int64_t c1, int64_t c2){
//     // cout<<start<<" ";
//     colors[start] = c2;
//     visited[start] = 1;
//     // *ctr = *ctr + 1;
//     // cout<<start<<" "<<*ctr<<"\n";
//     // int t = nodes[start].size();
//     // *max_degree = max(*max_degree, t);
//     // bool temp=false;
//     // cout<<start<<" "<<initial[start]<<" "<<after[start]<<"\n";
//     int64_t color_ctr=1;
//     for(int i=0;i<nodes[start].size();i++){
//         if(visited[nodes[start][i]]==0){
//             while(color_ctr==c1 || color_ctr==c2)
//                 color_ctr++;

//             DFS(nodes[start][i], c2, color_ctr);
//             color_ctr += 1;

//         }
//     }
// }

int64_t LCA(int64_t a, int64_t b){
    while(a!=b){
        // cout<<a<<" "<<b<<"\n";
        if(b>a){
            swap(a, b);
        }
        a /= 2;
    }
    return a;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m, a, b, i, j;
    cin>>n>>m;
    vector<vector<int> > nodes(n+1);
    for(i=0;i<m;i++){
        cin>>a>>b;
        nodes[a].push_back(b);
        nodes[b].push_back(a);
    }
    // cout<<"done;";
    vector<int> partition(n+1, -1); // visited(n+1, 0),
    for(i=1;i<n+1;i++){
        if(partition[i]==-1){
            queue<int> q;
            q.push(i);
            // q.push(-1);
            partition[i] = 0;
            int flag = 1;
            while(!q.empty()){
                int temp = q.front();
                q.pop();
                if(partition[temp]==0)
                    flag = 1;
                else
                    flag = 0;
                // if(temp==-1){
                //     if(!q.empty())
                //         q.push(-1);
                //     flag = flag ^ 1;
                //     continue;
                // }
                // cout<<"f "<<flag<<" "<<temp<<"\n";
                for(j=0;j<nodes[temp].size();j++){
                    // cout<<"p "<<nodes[temp][j]<<" "<<partition[nodes[temp][j]]<<"\n";
                    if(partition[nodes[temp][j]]==-1){
                        partition[nodes[temp][j]] = flag;
                        q.push(nodes[temp][j]);
                    }
                    else if(partition[nodes[temp][j]]==partition[temp]){
                        cout<<"-1\n";
                        return 0;
                    }
                }
            }
        }
    }
    vector<int> nodes_1, nodes_2;
    for(i=1;i<=n;i++){
        if(partition[i]==0)
            nodes_1.push_back(i);
        else if(partition[i]==1)
            nodes_2.push_back(i);
    }
    cout<<nodes_1.size()<<"\n";
    for(i=0;i<nodes_1.size();i++)
        cout<<nodes_1[i]<<" ";
    cout<<"\n";
    cout<<nodes_2.size()<<"\n";
    for(i=0;i<nodes_2.size();i++)
        cout<<nodes_2[i]<<" ";
    cout<<"\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

bool custom(pair<int64_t, vector<int64_t> > a, pair<int64_t, vector<int64_t> > b){
    // if(a.second.size()==b.second.size())
    //     return a.first > b.first;
    return a.second.size() > b.second.size();
}

bool customS1(pair<int, int> a, pair<int, int> b){
    // if(a.second==b.second)
    //     return a.first > b.first;
    return a.second < b.second;
}

bool customS2(pair<int, int> a, pair<int, int> b){
    if((a.first+a.second)==(b.first+b.second))
        return a.second < b.second;
    return (a.first+a.second)<(b.first+b.second);
}

class CompareDist
{
public:
    bool operator()(pair<int64_t, int64_t> a, pair<int64_t, int64_t> b){
        return a.first < b.first;
    }
};

int64_t gcd(int64_t a, int64_t b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

double gcdfloat(double a, double b) {
    if (a < b)
        return gcd(b, a);

    if (fabs(b) < 0.001)
        return a;

    else
        return (gcd(b, a - floor(a / b) * b));
}

// vector<int64_t> colors(200001, -1);
// // queue<int> q;

// void DFS(int64_t start, int64_t c1, int64_t c2){
//     // cout<<start<<" ";
//     colors[start] = c2;
//     visited[start] = 1;
//     // *ctr = *ctr + 1;
//     // cout<<start<<" "<<*ctr<<"\n";
//     // int t = nodes[start].size();
//     // *max_degree = max(*max_degree, t);
//     // bool temp=false;
//     // cout<<start<<" "<<initial[start]<<" "<<after[start]<<"\n";
//     int64_t color_ctr=1;
//     for(int i=0;i<nodes[start].size();i++){
//         if(visited[nodes[start][i]]==0){
//             while(color_ctr==c1 || color_ctr==c2)
//                 color_ctr++;

//             DFS(nodes[start][i], c2, color_ctr);
//             color_ctr += 1;

//         }
//     }
// }

int64_t LCA(int64_t a, int64_t b){
    while(a!=b){
        // cout<<a<<" "<<b<<"\n";
        if(b>a){
            swap(a, b);
        }
        a /= 2;
    }
    return a;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m, a, b, i, j;
    cin>>n>>m;
    vector<vector<int> > nodes(n+1);
    for(i=0;i<m;i++){
        cin>>a>>b;
        nodes[a].push_back(b);
        nodes[b].push_back(a);
    }
    // cout<<"done;";
    vector<int> partition(n+1, -1); // visited(n+1, 0),
    for(i=1;i<n+1;i++){
        if(partition[i]==-1){
            queue<int> q;
            q.push(i);
            // visited[i] = 1;
            partition[i] = 0;
            int flag = 0;
            while(!q.empty()){
                flag = flag ^ 1;
                int temp = q.front();
                q.pop();
                // cout<<"f "<<flag<<" "<<temp<<"\n";
                for(j=0;j<nodes[temp].size();j++){
                    // cout<<"p "<<nodes[temp][j]<<" "<<partition[nodes[temp][j]]<<"\n";
                    if(partition[nodes[temp][j]]==-1){
                        partition[nodes[temp][j]] = flag;
                        q.push(nodes[temp][j]);
                    }
                    else if(partition[nodes[temp][j]]==partition[temp]){
                        cout<<"-1\n";
                        return 0;
                    }
                }
            }
        }
        break;
    }
    vector<int> nodes_1, nodes_2;
    for(i=1;i<=n;i++){
        if(partition[i]==0)
            nodes_1.push_back(i);
        else if(partition[i]==1)
            nodes_2.push_back(i);
    }
    cout<<nodes_1.size()<<"\n";
    for(i=0;i<nodes_1.size();i++)
        cout<<nodes_1[i]<<" ";
    cout<<"\n";
    cout<<nodes_2.size()<<"\n";
    for(i=0;i<nodes_2.size();i++)
        cout<<nodes_2[i]<<" ";
    cout<<"\n";
    return 0;
}