import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.StringTokenizer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author saket
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		FlagDay solver = new FlagDay();
		solver.solve(1, in, out);
		out.close();
	}
}

class FlagDay {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
        int n=in.readInt();
        int m=in.readInt();
        int a[]=new int[n+1];
        for(int i=0;i<m;++i)
        {
           int dancers[]=new int[4];
           int sum=0;
            for(int j=1;j<=3;++j)
            {
                dancers[j]=in.readInt();
                sum+=a[dancers[j]];
            }
            int j=1;
            for(int k=1;k<=3;k++)
                if(sum!=k)
                {
                    while (a[dancers[j]]!=0)j++;
                    a[dancers[j]]=k;
                }
        }
        for(int i=1;i<=n;++i)
            out.print((a[i])+" ");
    }
}

class InputReader {
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int readInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}

class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public void print(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void close() {
        writer.close();
    }

}


import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class A {

	/* Write your custom/own functions here */
	public static void main(String[] ar) {
		Scanner sc = new Scanner(System.in);
		PrintStream ps = new PrintStream(new BufferedOutputStream(System.out),
				false);
		int n = sc.nextInt();
		int m = sc.nextInt();
//		Map<Integer, List<Integer>> next = new HashMap<Integer, List<Integer>>();
//		for (int i = 0; i < n; i++) {
//			next.put(i, new ArrayList<Integer>());
//		}
		int[][] in = new int[m][3];
		int[] ans = new int[n];
		for (int i = 0; i < m; i++) {
			in[i][0] = sc.nextInt() - 1;
			in[i][1] = sc.nextInt() - 1;
			in[i][2] = sc.nextInt() - 1;
//			for (int j = 0; j < 3; j++) {
//				next.get(in[i][j]).add(i);
//			}
			// System.out.println(Arrays.toString(in[i]));
		}
		// System.out.println();
		for (int i = 0; i < m; i++) {
			// System.out.println("i : " + i);
			List<Integer> allowed = new ArrayList<Integer>(Arrays.asList(1, 2,
					3));
			for (int j = 0; j < 3; j++) {
				if (ans[in[i][j]] != 0) {
//					System.out.println("lol");
					allowed.remove(ans[in[i][j]]);
				}
			}
			// System.out.println(allowed +" -< ");
			Iterator<Integer> lol = allowed.iterator();
			for (int j = 0; j < 3; j++) {
				int idx = in[i][j];
				if (ans[idx] == 0) {
					ans[idx] = lol.next();
				}
			}
		}
		ps.println(Arrays.toString(ans).replaceAll("[\\[\\],]", ""));

		ps.flush();
		ps.close();
		sc.close();
	}
}


import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class A {

	/* Write your custom/own functions here */
	public static void main(String[] ar) {
		Scanner sc = new Scanner(System.in);
		PrintStream ps = new PrintStream(new BufferedOutputStream(System.out),
				false);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[][] in = new int[m][3];
		int[] ans = new int[n];
		for (int i = 0; i < m; i++) {
			in[i][0] = sc.nextInt() - 1;
			in[i][1] = sc.nextInt() - 1;
			in[i][2] = sc.nextInt() - 1;
		}
		// System.out.println();
		for (int i = 0; i < m; i++) {
			// System.out.println("i : " + i);
			List<Integer> allowed = new ArrayList<Integer>(Arrays.asList(1, 2,
					3));
//			System.out.println("ALlowc:Ed" + allowed);
//			System.out.println("TryinG: " + Arrays.toString(in[i]));
//			System.out.println("Ans: " + Arrays.toString(ans));
			for (int j = 0; j < 3; j++) {
				if (ans[in[i][j]] != 0) {
//					System.out.println("Removing: " + ans[in[i][j]]);
					allowed.remove((Integer)ans[in[i][j]]);
				}
			}
//			System.out.println(allowed);
			Iterator<Integer> lol = allowed.iterator();
			Arrays.sort(in[i]);

			for (int j = 0; j < 3; j++) {
				if (ans[in[i][j]] == 0) {
					ans[in[i][j]] = lol.next();
				}
			}
		}
		ps.println(Arrays.toString(ans).replaceAll("[\\[\\],]", ""));

		ps.flush();
		ps.close();
		sc.close();
	}
}


import java.util.*;
public class Tanzor {
    public static void main (String[] args) {
        Scanner sm = new Scanner(System.in);
        int n = sm.nextInt();
        int m = sm.nextInt();
        int paryTanzorov [][] = new int[m][];
        for (int i = 0;i<m; i++){
            paryTanzorov[i]= new int[3];
            for (int j=0; j<3; j++)
                paryTanzorov[i][j]=sm.nextInt();
        }
        int cveta [] = new int[n+1];
        for (int i =0; i<m;i++) {
            if (Tanzor.nomer(paryTanzorov[i], cveta)){
                if (cveta[paryTanzorov[i][0]]!=1)
                    cveta[paryTanzorov[i][1]]=1;
                else cveta[paryTanzorov[i][1]]=2;
                cveta[paryTanzorov[i][2]]=6-cveta[paryTanzorov[i][1]]-cveta[paryTanzorov[i][0]];
            } else {
                cveta[paryTanzorov[i][0]]=1;
                cveta[paryTanzorov[i][1]]=2;
                cveta[paryTanzorov[i][2]]=3;
            }
        }
        for (int i =1; i<n+1;i++)
            System.out.print(cveta[i]+" ");
    }
    public static boolean nomer(int tanec[], int cveta[]){
        for (int i=0; i<tanec.length;i++){
            if (cveta[tanec[i]]>=1){
                int k = tanec[0];
                tanec[0]=tanec[i];
                tanec[i]=k;
                return true;
            }
        }
        return false;
    }
}


/* Codeforces Template */

import static java.util.Arrays.sort;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collection;
import java.util.Locale;
import java.util.Random;
import java.util.StringTokenizer;

public class Main {
    public void run() throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        while (!EOF())
            solve();
        out.close();
        in.close();
    }

    void solve() throws IOException {
        int n = nextInt();
        int m = nextInt();
        int[][] dance = new int[m][3];
        for (int i = 0; i < m; i++)
            dance[i] = nextIntArray(3);
        int[] color = new int[n + 1];
        // 1 for white, 2 for red, 3 for blue
        int count = 0;
        Arrays.fill(color, -1);
        for (int i = 0; i < m; i++) {
            count = 0;
            for (int j = 0; j < 3; j++)
                if (color[dance[i][j]] == -1) {
                    for (int k = 0; k < 3; k++)
                        if (color[dance[i][k]] == count)
                            count++;
                    color[dance[i][j]] = count % 3;
                    count++;

                }
        }
        for (int i = 1; i <= n; i++)
            System.out.print(color[i] + 1 + " ");
        System.out.println();

    }

    static long initTime;
    static final Random rnd = new Random(7777L);
    static boolean writeLog = false;

    public static void main(String[] args) throws IOException {
        initTime = System.currentTimeMillis();
        try {
            writeLog = "true".equals(System.getProperty("LOCAL_RUN_7777"));
        } catch (SecurityException e) {
        }
        new Thread(null, new Runnable() {
            public void run() {
                try {
                    try {
                        if (new File("input.txt").exists())
                            System.setIn(new FileInputStream("input.txt"));
                    } catch (SecurityException e) {
                    }
                    long prevTime = System.currentTimeMillis();
                    new Main().run();
                    log("Total time: "
                            + (System.currentTimeMillis() - prevTime) + " ms");
                    log("Memory status: " + memoryStatus());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }, "1", 1L << 24).start();
    }

    /***************************************************************
     * Input
     **************************************************************/
    BufferedReader in;
    PrintWriter out;
    StringTokenizer st = new StringTokenizer("");

    String nextToken() throws IOException {
        while (!st.hasMoreTokens())
            st = new StringTokenizer(in.readLine());
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    int[] nextIntArray(int size) throws IOException {
        int[] ret = new int[size];
        for (int i = 0; i < size; i++)
            ret[i] = nextInt();
        return ret;
    }

    long[] nextLongArray(int size) throws IOException {
        long[] ret = new long[size];
        for (int i = 0; i < size; i++)
            ret[i] = nextLong();
        return ret;
    }

    double[] nextDoubleArray(int size) throws IOException {
        double[] ret = new double[size];
        for (int i = 0; i < size; i++)
            ret[i] = nextDouble();
        return ret;
    }

    String nextLine() throws IOException {
        st = new StringTokenizer("");
        return in.readLine();
    }

    boolean EOF() throws IOException {
        while (!st.hasMoreTokens()) {
            String s = in.readLine();
            if (s == null)
                return true;
            st = new StringTokenizer(s);
        }
        return false;
    }

    /***************************************************************
     * Output
     **************************************************************/
    void printRepeat(String s, int count) {
        for (int i = 0; i < count; i++)
            out.print(s);
    }

    void printArray(int[] array) {
        if (array == null || array.length == 0)
            return;
        for (int i = 0; i < array.length; i++) {
            if (i > 0)
                out.print(' ');
            out.print(array[i]);
        }
        out.println();
    }

    void printArray(long[] array) {
        if (array == null || array.length == 0)
            return;
        for (int i = 0; i < array.length; i++) {
            if (i > 0)
                out.print(' ');
            out.print(array[i]);
        }
        out.println();
    }

    void printArray(double[] array) {
        if (array == null || array.length == 0)
            return;
        for (int i = 0; i < array.length; i++) {
            if (i > 0)
                out.print(' ');
            out.print(array[i]);
        }
        out.println();
    }

    void printArray(double[] array, String spec) {
        if (array == null || array.length == 0)
            return;
        for (int i = 0; i < array.length; i++) {
            if (i > 0)
                out.print(' ');
            out.printf(Locale.US, spec, array[i]);
        }
        out.println();
    }

    void printArray(Object[] array) {
        if (array == null || array.length == 0)
            return;
        boolean blank = false;
        for (Object x : array) {
            if (blank)
                out.print(' ');
            else
                blank = true;
            out.print(x);
        }
        out.println();
    }

    @SuppressWarnings("rawtypes")
    void printCollection(Collection collection) {
        if (collection == null || collection.isEmpty())
            return;
        boolean blank = false;
        for (Object x : collection) {
            if (blank)
                out.print(' ');
            else
                blank = true;
            out.print(x);
        }
        out.println();
    }

    /***************************************************************
     * Utility
     **************************************************************/
    static String memoryStatus() {
        return (Runtime.getRuntime().totalMemory()
                - Runtime.getRuntime().freeMemory() >> 20)
                + "/" + (Runtime.getRuntime().totalMemory() >> 20) + " MB";
    }

    static void checkMemory() {
        System.err.println(memoryStatus());
    }

    static long prevTimeStamp = Long.MIN_VALUE;

    static void updateTimer() {
        prevTimeStamp = System.currentTimeMillis();
    }

    static long elapsedTime() {
        return (System.currentTimeMillis() - prevTimeStamp);
    }

    static void checkTimer() {
        System.err.println(elapsedTime() + " ms");
    }

    static void chk(boolean f) {
        if (!f)
            throw new RuntimeException("Assert failed");
    }

    static void chk(boolean f, String format, Object... args) {
        if (!f)
            throw new RuntimeException(String.format(format, args));
    }

    static void log(String format, Object... args) {
        if (writeLog)
            System.err.println(String.format(Locale.US, format, args));
    }

    static void swap(int[] a, int i, int j) {
        int tmp = a[i];
        a[i] = a[j];
        a[j] = tmp;
    }

    static void swap(long[] a, int i, int j) {
        long tmp = a[i];
        a[i] = a[j];
        a[j] = tmp;
    }

    static void swap(double[] a, int i, int j) {
        double tmp = a[i];
        a[i] = a[j];
        a[j] = tmp;
    }

    static void shuffle(int[] a, int from, int to) {
        for (int i = from; i < to; i++)
            swap(a, i, rnd.nextInt(a.length));
    }

    static void shuffle(long[] a, int from, int to) {
        for (int i = from; i < to; i++)
            swap(a, i, rnd.nextInt(a.length));
    }

    static void shuffle(double[] a, int from, int to) {
        for (int i = from; i < to; i++)
            swap(a, i, rnd.nextInt(a.length));
    }

    static void shuffle(int[] a) {
        if (a == null)
            return;
        shuffle(a, 0, a.length);
    }

    static void shuffle(long[] a) {
        if (a == null)
            return;
        shuffle(a, 0, a.length);
    }

    static void shuffle(double[] a) {
        if (a == null)
            return;
        shuffle(a, 0, a.length);
    }

    static long[] getPartialSums(int[] a) {
        final long[] sums = new long[a.length + 1];
        for (int i = 0; i < a.length; i++)
            sums[i + 1] = sums[i] + a[i];
        return sums;
    }

    static long[] getPartialSums(long[] a) {
        final long[] sums = new long[a.length + 1];
        for (int i = 0; i < a.length; i++)
            sums[i + 1] = sums[i] + a[i];
        return sums;
    }

    static int[] getOrderedSet(int[] a) {
        final int[] set = Arrays.copyOf(a, a.length);
        if (a.length == 0)
            return set;
        shuffle(set);
        sort(set);
        int k = 1;
        int prev = set[0];
        for (int i = 1; i < a.length; i++) {
            if (prev != set[i]) {
                set[k++] = prev = set[i];
            }
        }
        return Arrays.copyOf(set, k);
    }

    static long[] getOrderedSet(long[] a) {
        final long[] set = Arrays.copyOf(a, a.length);
        if (a.length == 0)
            return set;
        shuffle(set);
        sort(set);
        int k = 1;
        long prev = set[0];
        for (int i = 1; i < a.length; i++) {
            if (prev != set[i]) {
                set[k++] = prev = set[i];
            }
        }
        return Arrays.copyOf(set, k);
    }
}


#include <iostream>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <list>
#include <fstream>
#include <set>
using namespace std;

#define REP(i,n) for (int i = 0; i < n; i++)
#define in(i) scanf("%d",&i)
#define out(i) printf("%d\n",i)
#define pii pair<int, int>
void fast_io() { cin.tie(0); ios::sync_with_stdio(false); }

typedef long long ll;
const ll MOD = 1000000007;
const double eps=1e-6;
typedef vector<vector<ll> > matrix;
//define matrix(KxK) as : matrix C(K+1, vector<ll>(K+1));
//map<int,int> m;
/*Check Time:
 clock_t startTime=clock()
 cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " seconds.";
 */
/*
 ll M(ll x,ll y)
 {
 return (x*y)%MOD;
 }
 ll A(ll x,ll y)
 {
 return (x+y)%MOD;
 }
 ll mod_pow(ll b,ll e)
 {
 if(e==0)    {return 1;}
 else if(e%2==0) {return mod_pow(M(b,b),e/2);}
 else    {return M(b,mod_pow(b,e-1));}
 }
 ll inv(ll x)
 {
 return mod_pow(x,MOD-2);    //using fermat's little theorem x^(p-1)=1 mod p (p is prime)
 }
 ll D(ll x,ll y)
 {
 return M(x,inv(y));
 }
 */
const int maxn=1e+5;
int n, m, a, b, c, col[maxn];
bool done[maxn];
int main(int argc, const char * argv[])
{
    cin>>n>>m;
    REP(i, m){
        cin>>a>>b>>c;
        if(done[b]) swap(a,b);
        if(done[c]) swap(a,c);
        col[b] = (col[a]+1)%3;
        col[c] = (col[a]+2)%3;
        done[a]=done[b]=done[c] = true;
    }
    for(int i = 1; i<=n; i++){
        cout<<col[i]+1<<" ";
    }
    return 0;
}


#include <iostream>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <list>
#include <fstream>
#include <set>
using namespace std;

#define REP(i,n) for (int i = 0; i < n; i++)
#define in(i) scanf("%d",&i)
#define out(i) printf("%d\n",i)
#define pii pair<int, int>
void fast_io() { cin.tie(0); ios::sync_with_stdio(false); }

typedef long long ll;
const ll MOD = 1000000007;
const double eps=1e-6;
typedef vector<vector<ll> > matrix;
//define matrix(KxK) as : matrix C(K+1, vector<ll>(K+1));
//map<int,int> m;
/*Check Time:
 clock_t startTime=clock()
 cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " seconds.";
 */
/*
 ll M(ll x,ll y)
 {
 return (x*y)%MOD;
 }
 ll A(ll x,ll y)
 {
 return (x+y)%MOD;
 }
 ll mod_pow(ll b,ll e)
 {
 if(e==0)    {return 1;}
 else if(e%2==0) {return mod_pow(M(b,b),e/2);}
 else    {return M(b,mod_pow(b,e-1));}
 }
 ll inv(ll x)
 {
 return mod_pow(x,MOD-2);    //using fermat's little theorem x^(p-1)=1 mod p (p is prime)
 }
 ll D(ll x,ll y)
 {
 return M(x,inv(y));
 }
 */
const int maxn=1e+5;
bool ar[300002];
int col[300002];

int main()
{
    int n,m;
    cin>>n>>m;
    while(m--)
    {
        int a,b,c;
        cin>>a>>b>>c;
        if(ar[b])
            swap(a,b);
        if(ar[c])
            swap(a,c);
        col[b]=(col[a]+1)%3;
        col[c]=(col[a]+2)%3;
        ar[a]=ar[b]=ar[c]=1;
    }
    for(int i=1;i<=n;++i)
        cout<<col[i]+1<<" ";
    return 0;
}


#include <iostream>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <list>
#include <fstream>
#include <set>
using namespace std;

#define REP(i,n) for (int i = 0; i < n; i++)
#define in(i) scanf("%d",&i)
#define out(i) printf("%d\n",i)
#define pii pair<int, int>
void fast_io() { cin.tie(0); ios::sync_with_stdio(false); }

typedef long long ll;
const ll MOD = 1000000007;
const double eps=1e-6;
typedef vector<vector<ll> > matrix;
//define matrix(KxK) as : matrix C(K+1, vector<ll>(K+1));
//map<int,int> m;
/*Check Time:
 clock_t startTime=clock()
 cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " seconds.";
 */
/*
 ll M(ll x,ll y)
 {
 return (x*y)%MOD;
 }
 ll A(ll x,ll y)
 {
 return (x+y)%MOD;
 }
 ll mod_pow(ll b,ll e)
 {
 if(e==0)    {return 1;}
 else if(e%2==0) {return mod_pow(M(b,b),e/2);}
 else    {return M(b,mod_pow(b,e-1));}
 }
 ll inv(ll x)
 {
 return mod_pow(x,MOD-2);    //using fermat's little theorem x^(p-1)=1 mod p (p is prime)
 }
 ll D(ll x,ll y)
 {
 return M(x,inv(y));
 }
 */
const int maxn=1e+5;

int cn[30], cm[30], ans;
string n, m;
int main(int argc, const char * argv[])
{
    cin>>n>>m;
    for(int i = 0; i<n.size(); i++){
        cn[n[i]-'a']++;
    }
    for(int i = 0; i<m.size(); i++){
        cm[m[i]-'a']++;
    }
    for(int i = 0; i<26; i++){
        if(cn[i]==0 && cm[i]!=0){
            cout<<-1;
            return 0;
        }
        ans+=min(cn[i], cm[i]);
    }
    cout<<ans;
    return 0;
}


#include <iostream>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <list>
#include <fstream>
#include <set>
using namespace std;

#define REP(i,n) for (int i = 0; i < n; i++)
#define in(i) scanf("%d",&i)
#define out(i) printf("%d\n",i)
#define pii pair<int, int>
void fast_io() { cin.tie(0); ios::sync_with_stdio(false); }

typedef long long ll;
const ll MOD = 1000000007;
const double eps=1e-6;
typedef vector<vector<ll> > matrix;
//define matrix(KxK) as : matrix C(K+1, vector<ll>(K+1));
//map<int,int> m;
/*Check Time:
 clock_t startTime=clock()
 cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " seconds.";
 */
/*
 ll M(ll x,ll y)
 {
 return (x*y)%MOD;
 }
 ll A(ll x,ll y)
 {
 return (x+y)%MOD;
 }
 ll mod_pow(ll b,ll e)
 {
 if(e==0)    {return 1;}
 else if(e%2==0) {return mod_pow(M(b,b),e/2);}
 else    {return M(b,mod_pow(b,e-1));}
 }
 ll inv(ll x)
 {
 return mod_pow(x,MOD-2);    //using fermat's little theorem x^(p-1)=1 mod p (p is prime)
 }
 ll D(ll x,ll y)
 {
 return M(x,inv(y));
 }
 */
const int maxn=1e+5;
int n, m, dance[maxn][3], ans[maxn];
int main(int argc, const char * argv[])
{
    cin>>n>>m;
    REP(i, m){
        REP(j, 3){
            cin>>dance[i][j];
        }
    }
    REP(i, m){
        if(ans[dance[i][0]]){
            ans[dance[i][1]] = ((ans[dance[i][0]]+1)%3);
            ans[dance[i][2]] = ((ans[dance[i][0]]+2)%3);
            if(!ans[dance[i][1]])   ans[dance[i][1]]=3;
            if(!ans[dance[i][2]])   ans[dance[i][2]]=3;
        }
        else if(ans[dance[i][1]]){
            ans[dance[i][0]] = ((ans[dance[i][1]]+1)%3);
            ans[dance[i][2]] = ((ans[dance[i][1]]+2)%3);
            if(!ans[dance[i][0]])   ans[dance[i][0]]=3;
            if(!ans[dance[i][2]])   ans[dance[i][2]]=3;
        }
        else if(ans[dance[i][2]]){
            ans[dance[i][1]] = ((ans[dance[i][2]]+1)%3);
            ans[dance[i][0]] = ((ans[dance[i][2]]+2)%3);
            if(!ans[dance[i][1]])   ans[dance[i][1]]=3;
            if(!ans[dance[i][0]])   ans[dance[i][0]]=3;
        }
        else{
            ans[dance[i][0]] = 1;
            ans[dance[i][1]] = 2;
            ans[dance[i][2]] = 3;
        }
    }
    for(int i = 1; i<=n; i++){
        cout<<ans[i]<<" ";
    }
    return 0;
}


#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
using namespace std;

const int maxn=111111;

int col[maxn],vis[4];

void solve(int a,int b,int c)
{
    int i;
    memset(vis,0,sizeof(vis));
    vis[col[a]]++;
    vis[col[b]]++;
    vis[col[c]]++;
    for(i=1;i<=3;i++)
    {
        if(!col[a]&&!vis[i])
        {
            col[a]=i;
            vis[i]=1;
        }
    }
    for(i=1;i<=3;i++)
    {
        if(!col[b]&&!vis[i])
        {
            col[b]=i;
            vis[i]=1;
        }
    }
    for(i=1;i<=3;i++)
    {
        if(!col[c]&&!vis[i])
        {
            col[c]=i;
            vis[i]=1;
        }
    }
}

int main()
{
    int n,m;
    int i;
    int a,b,c;
    scanf("%d%d",&n,&m);
    memset(col,0,sizeof(col));
    for(i=0;i<m;i++)
    {
        scanf("%d%d%d",&a,&b,&c);
        solve(a,b,c);
    }
    for(i=1;i<=n;i++)
    {
        if(i>1)
            cout<<" ";
        cout<<col[i];
    }
    return 0;
}


#include<bits/stdc++.h>
#include <vector>
using namespace std;
#define rep(i,b) for (ll i =0; i < (b); i++)
typedef long long ll;

// ---** Functions **---
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
// ---** START FROM HERE **---
int n ,m; cin>>n>>m;
int arr[n+1]; memset(arr,0,sizeof(arr));
int brr[n+1];
while(m--){
    int x,y,z; cin>>x>>y>>z;
    if(arr[x]!=0){
        arr[y]=arr[x]%3+1;
        arr[z]=arr[y]%3+1;
    }
    else if(arr[y]!=0){
        arr[z]=arr[y]%3+1;
        arr[x]=arr[z]%3+1;
    }
    else{
        if(arr[z]==0) arr[z]=1;
        arr[x]=arr[z]%3+1;
        arr[y]=arr[x]%3+1;
    }

}
for(int i=1; i<=n; i++){
    cout<<arr[i]<<" ";
}cout<<endl;

return 0;

}


#include<bits/stdc++.h>
#include <vector>
using namespace std;
#define rep(i,b) for (ll i =0; i < (b); i++)
typedef long long ll;

// ---** Functions **---
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
// ---** START FROM HERE **---
int n ,m; cin>>n>>m;
int arr[n+1]; memset(arr,0,sizeof(arr));
int brr[n+1];
while(m--){
    int x,y,z; cin>>x>>y>>z;
    if(arr[x]!=0){
        arr[y]=arr[x]%3+1;
        arr[z]=arr[y]%3+2;
    }
    else if(arr[y]!=0){
        arr[z]=arr[y]%3+1;
        arr[x]=arr[z]%3+1;
    }
    else{
        if(arr[z]==0) arr[z]=1;
        arr[x]=arr[z]%3+1;
        arr[y]=arr[x]%3+1;
    }

}
for(int i=1; i<=n; i++){
    cout<<arr[i]<<" ";
}cout<<endl;

return 0;

}


/* -*- coding: utf-8; tab-width: 4 -*- */

#include <cstdio>
#include <vector>
#include <algorithm>

int c[100000];
std::vector<int> e[100000];
int f[100000][3];

bool
search(int n,
	   int k = 0)
{
	if (n == k) return true;

	for (int i(0); i < 3; ++i) {
		if (0 < f[k][i]) continue;
		for (int j : e[k]) f[j][i]++;
		c[k] = i;
		if (search(n, k + 1)) return true;
		for (int j : e[k]) f[j][i]--;
	}

	return false;
}

int
main()
{
	int n, m, p[3];

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

	while (0 < m--) {
		std::scanf("%d%d%d", p, p+1, p+2);
		p[0]--, p[1]--, p[2]--;
		std::sort(p, p + 3);
		e[p[0]].push_back(p[1]);
		e[p[0]].push_back(p[2]);
		e[p[1]].push_back(p[2]);
	}

	search(n);

	for (int i(0); i < n; ++i) {
//		std::printf("[%d] %d\n", i + 1, c[i] + 1);
		if (0 < i) std::printf(" ");
		std::printf("%d", c[i] + 1);
	}
	std::puts("");

	return 0;
}


/* -*- coding: utf-8; tab-width: 4 -*- */

#include <cstdio>
#include <vector>
#include <algorithm>

int c[100000];
std::vector<int> e[100000];
int f[100000][3];

bool
search(int n,
	   int k = 0)
{
	if (n == k) return true;

	for (int i(1); i <= 3; ++i) {
		if (0 < f[k][i]) continue;
		for (int j : e[k]) f[j][i]++;
		c[k] = i;
		if (search(n, k + 1)) return true;
		for (int j : e[k]) f[j][i]--;
	}

	return false;
}

int
main()
{
	int n, m, p[3];

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

	while (0 < m--) {
		std::scanf("%d%d%d", p, p+1, p+2);
		p[0]--, p[1]--, p[2]--;
		std::sort(p, p + 3);
		e[p[0]].push_back(p[1]);
		e[p[0]].push_back(p[2]);
		e[p[1]].push_back(p[2]);
	}

	search(n);

	for (int i(0); i < n; ++i) {
//		std::printf("[%d] %d\n", i + 1, c[i]);
		if (0 < i) std::printf(" ");
		std::printf("%d", c[i]);
	}
	std::puts("");

	return 0;
}


/* -*- coding: utf-8; tab-width: 4 -*- */

#include <cstdio>
#include <vector>
#include <algorithm>

int c[100000];
std::vector<int> e[100000];

bool
search(int n,
	   int k = 0)
{
	if (n == k) return true;

	for (int i(1); i <= 3; ++i) {
		for (int j : e[k]) {
			if (i == c[j]) goto N;
		}
		c[k] = i;
		if (search(n, k + 1)) return true;
	N:
		;
	}

	return false;
}

int
main()
{
	int n, m, p[3];

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

	while (0 < m--) {
		std::scanf("%d%d%d", p, p+1, p+2);
		p[0]--, p[1]--, p[2]--;
		std::sort(p, p + 3);
		e[p[1]].push_back(p[0]);
		e[p[2]].push_back(p[0]);
		e[p[2]].push_back(p[1]);
	}

	search(n);

	for (int i(0); i < n; ++i) {
//		std::printf("[%d] %d\n", i + 1, c[i]);
		if (0 < i) std::printf(" ");
		std::printf("%d", c[i]);
	}
	std::puts("");

	return 0;
}


#include<bits/stdc++.h>
#define cin(a) cin>>a;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define cout(a) cout<<a;
#define new() cout<<endl;
#define f first
#define s second
#define fill(a,x) memset(a,x,sizeof(a));
#define loop(i,x,n) for(int i=x;i<n;i++)
#define TC() ll t;cin>>t;while(t--)
typedef long long ll;
#define MOD 1000000007
#define SIZE 100020
#define vec vector<ll>
#define vmp vector<pair<ll,ll> >
#define pb push_back
#define mp make_pair
#define all(a)         a.begin(), a.end()
#define ull unsigned long long
using namespace std;
int main()
{
   IOS;
   ll n,m;
   cin>>n>>m;
   vec c(n,-1);
   loop(i,0,m)
   {
       ll x,y,z;
       bool f[3];
       memset(f,false,sizeof(f));
       cin>>x>>y>>z;
       if(c[x-1]==-1&&c[y-1]==-1&&c[z-1]==-1)
        {
            c[x-1]=1,c[y-1]=2,c[z-1]=3;
        }
        else{
        if(c[x-1]!=-1)
            f[c[x-1]-1]=true;
        if(c[y-1]!=-1)
            f[c[y-1]-1]=true;
        if(c[z-1]!=-1)
            f[c[z-1]-1]=true;
        if(c[x-1]==-1)
        {
            for(ll j=0;j<3;j++)
            {
                if(f[j]==false)
                {
                    c[x-1]=j+1;
                    f[j]=true;
                    break;
                }
            }
        }
        if(c[y-1]==-1)
        {
            for(ll j=0;j<3;j++)
            {
                if(f[j]==false)
                {
                    c[y-1]=j+1;
                    f[j]=true;
                    break;
                }
            }
        }
        if(c[z-1]==-1)
        {
            for(ll j=0;j<3;j++)
            {
                if(f[j]==false)
                {
                    c[z-1]=j+1;
                    f[j]=true;
                    break;
                }
            }
        }
        }
   }
   loop(i,0,n)
   cout<<c[i]<<" ";

   return 0;
}


#include<bits/stdc++.h>
#define cin(a) cin>>a;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define cout(a) cout<<a;
#define new() cout<<endl;
#define f first
#define s second
#define fill(a,x) memset(a,x,sizeof(a));
#define loop(i,x,n) for(int i=x;i<n;i++)
#define TC() ll t;cin>>t;while(t--)
typedef long long ll;
#define MOD 1000000007
#define SIZE 100020
#define vec vector<ll>
#define vmp vector<pair<ll,ll> >
#define pb push_back
#define mp make_pair
#define all(a)         a.begin(), a.end()
#define ull unsigned long long
using namespace std;
int main()
{
   IOS;
   ll n,m;
   cin>>n>>m;
   vec c(n,-1);
   loop(i,0,m)
   {
       ll x,y,z;
       bool f[3];
       memset(f,false,sizeof(f));
       cin>>x>>y>>z;
       if(c[x-1]==-1&&c[y-1]==-1&&c[z-1]==-1)
        {
            c[x-1]=1,c[y-1]=2,c[z-1]=3;
        }
        else{
        if(c[x-1]!=-1)
            f[c[x-1]-1]=true;
        if(c[y-1]!=-1)
            f[c[y-1]!=-1]=true;
        if(c[z-1]!=-1)
            f[c[z-1]-1]=true;
        if(c[x-1]==-1)
        {
            for(ll j=0;j<3;j++)
            {
                if(f[j]==false)
                {
                    c[x-1]=j+1;
                    f[j]=true;
                    break;
                }
            }
        }
        if(c[y-1]==-1)
        {
            for(ll j=0;j<3;j++)
            {
                if(f[j]==false)
                {
                    c[y-1]=j+1;
                    f[j]=true;
                    break;
                }
            }
        }
        if(c[z-1]==-1)
        {
            for(ll j=0;j<3;j++)
            {
                if(f[j]==false)
                {
                    c[z-1]=j+1;
                    f[j]=true;
                    break;
                }
            }
        }
        }
   }
   loop(i,0,n)
   cout<<c[i]<<" ";

   return 0;
}


#include<bits/stdc++.h>
#define cin(a) cin>>a;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define cout(a) cout<<a;
#define new() cout<<endl;
#define f first
#define s second
#define fill(a,x) memset(a,x,sizeof(a));
#define loop(i,x,n) for(int i=x;i<n;i++)
#define TC() ll t;cin>>t;while(t--)
typedef long long ll;
#define MOD 1000000007
#define SIZE 100020
#define vec vector<ll>
#define vmp vector<pair<ll,ll> >
#define pb push_back
#define mp make_pair
#define all(a)         a.begin(), a.end()
#define ull unsigned long long
using namespace std;
int main()
{
   IOS;
   ll n,m;
   cin>>n>>m;
   vec c(n,-1);
   loop(i,0,m)
   {
       ll x,y,z;
       cin>>x>>y>>z;
       if(c[x-1]==-1)
        c[x-1]=1;
       if(c[y-1]==-1)
        c[y-1]=2;
       if(c[z-1]==-1)
        c[z-1]=3;
   }
   loop(i,0,n)
   cout<<c[i]<<" ";
   return 0;
}


#include <bits/stdc++.h>
using namespace std;
int res[100010];

int main(){
	int n, m;
	cin>>n>>m;
	while(m--){
		int a, b, c;
		cin>>a>>b>>c;
		if (res[a] != 0){
			res[b] = res[a]%3+1;
			res[c] = (res[a]+1)%3+1;
		}
		else if (res[b] != 0){
			res[a] = res[b]%3+1;
			res[c] = (res[b]+1)%3+1;
		}
		else if (res[c] != 0){
			res[a] = res[c]%3+1;
			res[b] = (res[c]%3+1)%3+1;
		}
		else{
			res[a] = 1;
			res[b] = 2;
			res[c] = 3;
		}
	}
	for (int i=1; i<=n; i++) cout<<res[i]<<" ";
}


#include <bits/stdc++.h>
using namespace std;
int res[100010];

int main(){
	int n, m;
	cin>>n>>m;
	while(m--){
		int a, b, c;
		cin>>a>>b>>c;
		if (res[a] != 0){
			res[b] = res[a]%3+1;
			res[c] = (res[a]+1)%3+1;
		}
		else if (res[b] != 0){
			res[a] = res[b]%3+1;
			res[c] = (res[b]+1)%3+1;
		}
		else if (res[c] != 0){
			res[a] = res[c]%3+1;
			res[b] = (res[c]%3+1)%3+1;
		}
		else{
			res[a] = 1;
			res[b] = 2;
			res[c] = 3;
		}
	}
	for (int i=0; i<n; i++) cout<<res[i]<<" ";
}


#include <iostream>
#include <algorithm>
using namespace std;
int i,n,m,a[100005],x,y,z;
int main()
{
    cin >> n >> m;
    while(m--)
    {
      cin >> x >> y >> z;
      if ( a[y] ) swap(x,y);
      if ( a[z] ) swap(x,z);
      if( !a[x] || a[x] == 1 ) a[x] = 1,a[y] = 2,a[z] = 3;
      else if(a[x] == 2) a[z] = 3, a[y] = 1;
           else a[y] = 1,a[z] = 2;
    }
    for(i = 1;i <= n;++i) cout << a[i] << " \n" [ i == n ];
   return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int a[100010];
int main()
{
	int n,m,x;
	cin >> n >> m;
	for(int i = 0;i < m;i++)
	{
		string s = "";
		for(int j = 0;j < 3;j++)
		{
			cin >> x;
			if(a[x] == 0)
			{
				for(int k = 1;k <= 3;k++)
				{
					if(find(s.begin(), s.end(),k + '0') == s.end())
					{
						a[x] = k;
						break;
					}
				}
			}
			s += a[x] + '0';
			//cout << "case : " << s << endl;
		}
	}
	for(int i = 1;i <= n;i++)
		cout << a[i] << " ";
	cout << endl;
}


#include<iostream>
#include<algorithm>
using namespace std;

int i,n,m,a[100005],x,y,z;

int main()
{
  ios_base::sync_with_stdio(0);

  cin>>n>>m;

  while(m--)
  {
    cin>>x>>y>>z;
    if(a[y]) swap(x,y);
    if(a[z]) swap(x,z);
    if(!a[x] || a[x]==1) a[x]=1,a[y]=2,a[z]=3;
    else if(a[x]==2) a[z]=3,a[y]=1;
         else a[y]=1,a[z]=2;
  }

  for(i=1;i<=n;++i) cout<<a[i]<<" \n"[i==n];

 return 0;
}


for (int i = 1; i <= m; i++)
	{
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		if (ans[a])
		{
			swap(a, c);
			if (ans[c] == 3)
				ans[a] = 1, ans[b] = 2;
			else if (ans[c] == 2)
				ans[a] = 1, ans[b] = 3;
			else
				ans[a] = 2, ans[b] = 3;
		}

		else if (ans[b])
		{
			swap(b, c);
			if (ans[c] == 3)
				ans[a] = 1, ans[b] = 2;
			else if (ans[c] == 2)
				ans[a] = 1, ans[b] = 3;
			else
				ans[a] = 2, ans[b] = 3;
		}

		else if (ans[c])
		{
			if (ans[c] == 3)
				ans[a] = 1, ans[b] = 2;
			else if (ans[c] == 2)
				ans[a] = 1, ans[b] = 3;
			else
				ans[a] = 2, ans[b] = 3;
		}

		else
			ans[a] = 1, ans[b] = 2, ans[c] = 3;
	}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    /*string s,t,q,r;
    cin>>s>>t>>q>>r;
    int x = s.length()-2;
    int y = t.length()-2,z = q.length()-2,w = r.length()-2;
   // cout<<x<<" "<<y<<" "<<z<<" "<<w<<endl;
    int choice1 = 0,choice2 = 0;

        if(2*x<=y&&2*x<=z&&2*x<=w) choice1 = x;
    else if((2*y<=x&&2*y<=z&&2*y<=w)) choice1 = y;
    else if(2*z<=x&&2*z<=y&&2*z<=w) choice1 = z;
    else if(2*w<=x&&2*w<=y&&2*w<=z) choice1 = w;

    if(x>=2*y&&x>=2*z&&x>=2*w) choice2 = x;
    else if((y>=2*x&&y>=2*z&&y>=2*w)) choice2 = y;
    else if(z>=2*x&&z>=2*y&&z>=2*w) choice2 = z;
    else if(w>=2*x&&w>=2*y&&w>=2*z) choice2 = w;

 // cout<<choice1<<" "<<choice2<<endl;
    if((choice1!=0&&choice2!=0)||(choice1==0&&choice2==0)) cout<<"C";
    else
    {
        if(choice1==x||choice2==x) cout<<"A";
        else if(choice1==y||choice2==y) cout<<"B";
        else if(choice1==z||choice2==z) cout<<"C";
        else if(choice1==w||choice2==w) cout<<"D";
    }*/
    int n,m;
    cin>>n>>m;
    int ans[n+1]={0};
   for (int i = 1; i <= m; i++)
	{
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		if (ans[a])
		{
			swap(a, c);
			if (ans[c] == 3)
				ans[a] = 1, ans[b] = 2;
			else if (ans[c] == 2)
				ans[a] = 1, ans[b] = 3;
			else
				ans[a] = 2, ans[b] = 3;
		}

		else if (ans[b])
		{
			swap(b, c);
			if (ans[c] == 3)
				ans[a] = 1, ans[b] = 2;
			else if (ans[c] == 2)
				ans[a] = 1, ans[b] = 3;
			else
				ans[a] = 2, ans[b] = 3;
		}

		else if (ans[c])
		{
			if (ans[c] == 3)
				ans[a] = 1, ans[b] = 2;
			else if (ans[c] == 2)
				ans[a] = 1, ans[b] = 3;
			else
				ans[a] = 2, ans[b] = 3;
		}

		else
			ans[a] = 1, ans[b] = 2, ans[c] = 3;
	}
    for(int i = 1;i<=n;i++)
    {
        cout<<ans[i]<<" ";
    }
    return 0;
}


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

int main()
{
    /*string s,t,q,r;
    cin>>s>>t>>q>>r;
    int x = s.length()-2;
    int y = t.length()-2,z = q.length()-2,w = r.length()-2;
   // cout<<x<<" "<<y<<" "<<z<<" "<<w<<endl;
    int choice1 = 0,choice2 = 0;

        if(2*x<=y&&2*x<=z&&2*x<=w) choice1 = x;
    else if((2*y<=x&&2*y<=z&&2*y<=w)) choice1 = y;
    else if(2*z<=x&&2*z<=y&&2*z<=w) choice1 = z;
    else if(2*w<=x&&2*w<=y&&2*w<=z) choice1 = w;

    if(x>=2*y&&x>=2*z&&x>=2*w) choice2 = x;
    else if((y>=2*x&&y>=2*z&&y>=2*w)) choice2 = y;
    else if(z>=2*x&&z>=2*y&&z>=2*w) choice2 = z;
    else if(w>=2*x&&w>=2*y&&w>=2*z) choice2 = w;

 // cout<<choice1<<" "<<choice2<<endl;
    if((choice1!=0&&choice2!=0)||(choice1==0&&choice2==0)) cout<<"C";
    else
    {
        if(choice1==x||choice2==x) cout<<"A";
        else if(choice1==y||choice2==y) cout<<"B";
        else if(choice1==z||choice2==z) cout<<"C";
        else if(choice1==w||choice2==w) cout<<"D";
    }*/
    int n,m;
    cin>>n>>m;
    int a[m+1][4];
    int ans[n+1];
    for(int i =1;i<=m;i++)
    {
        for(int j = 1;j<=3;j++)
        {
            cin>>a[i][j];
            ans[a[i][j]] = j;
        }
    }
    for(int i = 1;i<=n;i++)
    {
        cout<<ans[i]<<" ";
    }
    return 0;
}


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

int main()
{
    /*string s,t,q,r;
    cin>>s>>t>>q>>r;
    int x = s.length()-2;
    int y = t.length()-2,z = q.length()-2,w = r.length()-2;
   // cout<<x<<" "<<y<<" "<<z<<" "<<w<<endl;
    int choice1 = 0,choice2 = 0;

        if(2*x<=y&&2*x<=z&&2*x<=w) choice1 = x;
    else if((2*y<=x&&2*y<=z&&2*y<=w)) choice1 = y;
    else if(2*z<=x&&2*z<=y&&2*z<=w) choice1 = z;
    else if(2*w<=x&&2*w<=y&&2*w<=z) choice1 = w;

    if(x>=2*y&&x>=2*z&&x>=2*w) choice2 = x;
    else if((y>=2*x&&y>=2*z&&y>=2*w)) choice2 = y;
    else if(z>=2*x&&z>=2*y&&z>=2*w) choice2 = z;
    else if(w>=2*x&&w>=2*y&&w>=2*z) choice2 = w;

 // cout<<choice1<<" "<<choice2<<endl;
    if((choice1!=0&&choice2!=0)||(choice1==0&&choice2==0)) cout<<"C";
    else
    {
        if(choice1==x||choice2==x) cout<<"A";
        else if(choice1==y||choice2==y) cout<<"B";
        else if(choice1==z||choice2==z) cout<<"C";
        else if(choice1==w||choice2==w) cout<<"D";
    }*/
    int n,m;
    cin>>n>>m;
    int ans[n+1]={0};
    for(int i =1;i<=m;i++)
    {
        int a,b,c;
       cin>>a>>b>>c;
       if(ans[a])
       {
           if(ans[a]==1) ans[b]=2,ans[c]=3;
          else if(ans[a]==2) ans[b]=1,ans[c]=3;
          else if(ans[a]==3) ans[b]=1,ans[c]=2;
       }
       if(ans[b])
       {
            if(ans[b]==1) ans[a]=2,ans[c]=3;
          else if(ans[b]==2) ans[a]=1,ans[c]=3;
          else if(ans[b]==3) ans[a]=1,ans[c]=2;
       }
       if(ans[c])
       {
           if(ans[c]==1) ans[b]=2,ans[a]=3;
          else if(ans[c]==2) ans[b]=1,ans[a]=3;
          else if(ans[c]==3) ans[b]=1,ans[a]=2;
       }
       else
       {
           ans[a] =1,ans[b] =2,ans[c] =  3;
       }
    }
    for(int i = 1;i<=n;i++)
    {
        cout<<ans[i]<<" ";
    }
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits\stdc++.h>
using namespace std;
#define For(i,a,b) for(int i=a;i<b;i++)
#define all(v)     (v).begin(),(v).end()
#define sz(v)      (ll) (v).size()
#define ll  long long
#define mem(a,val) memset(a,val,sizeof(a))
#define sc1(n) scanf("%I64d",&n)
#define sc2(n,m) scanf("%I64d %I64d",&n,&m)
#define sc3(n,m,x) scanf("%I64d %I64d %I64d",&n,&m,&x)
#define pf1(n) printf("%I64d",n)
#define pf2(n,m) printf("%I64d %I64d",n,m)
#define pf  printf
#define sc scanf
#define mp make_pair
#define endl '\n'
#define d(x) {cerr <<#x <<" = " <<x <<endl; }
#define d2(x,y) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y <<endl; }
#define d3(x,y,z) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y << ", " << #z << " = " << z <<endl; }
#define dp(a){cerr<<#a<<" = first :"<<a.first<<"  , second : "<<a.second<<endl;;}
#define dv(x) {cerr <<#x <<" = ";for(int i=0;i<sz(x);i++) cerr <<x[i] <<", "; cerr <<endl; }
#define Max 0x3f3f3f3f3f3f3f3fLL
typedef pair<ll, ll>pii;
typedef vector<ll>vi;
typedef vector<pii>vp;
typedef vector<string>vs;
inline void hoba(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
int main(){
    //hoba();
    ll n, m, a, b, c;
    sc2(n, m);
    map<ll, char>arr;
    For(i, 0, m){
        sc3(a, b, c);
        if (arr[a] || arr[b] || arr[c]){
            if (arr[a] == '1'){
                arr[b] = '2';
                arr[c] = '3';
            }
            else if (arr[a] == '2'){
                arr[b] = '1';
                arr[c] = '3';
            }
            else if (arr[a] == '3'){
                arr[b] = '1';
                arr[c] = '2';
            }
            else if (arr[b] == '1'){
                arr[a] = '2';
                arr[c] = '3';
            }
            else if (arr[b] == '2'){
                arr[a] = '1';
                arr[c] = '3';
            }
            else if (arr[b] == '3'){
                arr[a] = '1';
                arr[c] = '2';
            }
            else if (arr[c] == '1'){
                arr[a] = '2';
                arr[b] = '3';
            }
            else if (arr[c] == '2'){
                arr[a] = '1';
                arr[b] = '3';
            }
            else if (arr[c] == '3'){
                arr[a] = '2';
                arr[b] = '1';
            }
        }
        else{
            arr[a] = '1';
            arr[b] = '2';
            arr[c] = '3';
        }
    }
    for (auto i : arr)
        cout << i.second << " ";

    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits\stdc++.h>
using namespace std;
#define For(i,a,b) for(int i=a;i<b;i++)
#define all(v)     (v).begin(),(v).end()
#define sz(v)      (ll) (v).size()
#define ll  long long
#define mem(a,val) memset(a,val,sizeof(a))
#define sc1(n) scanf("%I64d",&n)
#define sc2(n,m) scanf("%I64d %I64d",&n,&m)
#define sc3(n,m,x) scanf("%I64d %I64d %I64d",&n,&m,&x)
#define pf1(n) printf("%I64d",n)
#define pf2(n,m) printf("%I64d %I64d",n,m)
#define pf  printf
#define sc scanf
#define mp make_pair
#define endl '\n'
#define d(x) {cerr <<#x <<" = " <<x <<endl; }
#define d2(x,y) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y <<endl; }
#define d3(x,y,z) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y << ", " << #z << " = " << z <<endl; }
#define dp(a){cerr<<#a<<" = first :"<<a.first<<"  , second : "<<a.second<<endl;;}
#define dv(x) {cerr <<#x <<" = ";for(int i=0;i<sz(x);i++) cerr <<x[i] <<", "; cerr <<endl; }
#define Max 0x3f3f3f3f3f3f3f3fLL
typedef pair<ll, ll>pii;
typedef vector<ll>vi;
typedef vector<pii>vp;
typedef vector<string>vs;
inline void hoba(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
map<char, string>l;
int main(){
    //hoba();
    ll n, m, a, b, c;
    sc2(n, m);
    l['1'] = "23";
    l['2'] = "31";
    l['3'] = "12";

    map<ll, char>arr;
    For(i, 0, m){
        sc3(a, b, c);
        if (arr[a] || arr[b] || arr[c]){
            if (arr[a]){
                arr[b] = l[arr[a]][0];
                arr[c] = l[arr[a]][1];
            }

            else if (arr[b]){
                arr[a] = l[arr[b]][0];
                arr[c] = l[arr[b]][1];
            }

            else if (arr[c]){
                arr[b] = l[arr[c]][0];
                arr[a] = l[arr[c]][1];
            }
        }
        else{
            arr[a] = '1';
            arr[b] = '2';
            arr[c] = '3';
        }
    }
    for (auto i : arr)
        cout << i.second << " ";

    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits\stdc++.h>
using namespace std;
#define For(i,a,b) for(int i=a;i<b;i++)
#define all(v)     (v).begin(),(v).end()
#define sz(v)      (ll) (v).size()
#define ll  long long
#define mem(a,val) memset(a,val,sizeof(a))
#define sc1(n) scanf("%I64d",&n)
#define sc2(n,m) scanf("%I64d %I64d",&n,&m)
#define sc3(n,m,x) scanf("%I64d %I64d %I64d",&n,&m,&x)
#define pf1(n) printf("%I64d",n)
#define pf2(n,m) printf("%I64d %I64d",n,m)
#define pf  printf
#define sc scanf
#define mp make_pair
#define endl '\n'
#define d(x) {cerr <<#x <<" = " <<x <<endl; }
#define d2(x,y) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y <<endl; }
#define d3(x,y,z) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y << ", " << #z << " = " << z <<endl; }
#define dp(a){cerr<<#a<<" = first :"<<a.first<<"  , second : "<<a.second<<endl;;}
#define dv(x) {cerr <<#x <<" = ";for(int i=0;i<sz(x);i++) cerr <<x[i] <<", "; cerr <<endl; }
#define Max 0x3f3f3f3f3f3f3f3fLL
typedef pair<ll, ll>pii;
typedef vector<ll>vi;
typedef vector<pii>vp;
typedef vector<string>vs;
inline void hoba(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
char l[3] = { '1', '2', '3' };
int main(){
    //hoba();
    ll n, m, a, in = 0;
    sc2(n, m);
    map<ll, char>arr;
    For(i, 0, m){
        For(y, 0, 3){
            sc1(a);
            if (!arr[a]){
                arr[a] = l[in];
                in++;
                (in == 3) ? in = 0 : 1;
            }
            else if (arr[i] == '1')
                in = 1;
            else if (arr[i] == '2')
                in = 2;
            else
                in = 0;
        }
    }
    for (auto i : arr)
        cout << i.second << " ";

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define all(v)            v.begin(),v.end()
#define allR(v)           v.rbegin(),v.rend()
#define V                 vector
#define S                 string
#define pb                push_back
#define pf                push_front
#define set(a,b)          memset(a,b,sizeof(a))
#define mp(a,b)           make_pair(a,b)
#define sz                size()
#define get               cin>>
#define print             cout<<
#define getArr(ar,n)      for(int i=0;i<n;get ar[i++])
#define printArr(ar,n)    for(int i=0;i<n;print ar[i++]<<' ')
#define OO 1e6
#define pii               pair<int,int>
#define Sort(ar,n)        sort(ar,ar+n)
#define getPoint(x,y)     get x>>y
#define dist(x1,y1,x2,y2) (x1-x2)*(x1-x2) + ((y1-y2)*(y1-y2))
#define file              freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define IO                cin.tie(0);std::ios::sync_with_stdio(false);
typedef long long ll;
typedef unsigned long long ull;
typedef double lf;
int dx[] = { 1 , -1 , 0 , 0 };
int dy[] = { 0 , 0 , 1 , -1 };
const ll mod = 1000000007;
const lf pi = 3.1415926536;
int main(){
    IO
    int n,m; get n>>m;
    int ans[n+1]; set(ans,0);
    for(int i=0;i<m;i++){
        int a,b,c; get a>>b>>c;
        int ar[]={1,2,3};
        if(ans[a])ar[ans[a]-1]=0;
        if(ans[b])ar[ans[b]-1]=0;
        if(ans[c])ar[ans[c]-1]=0;
        for(int i=0;i<n;i++){
            if(!ans[a]&&ar[i]){
                ans[a]=ar[i];
                ar[i]=0; continue;
            }
            if(!ans[b]&&ar[i]){
                ans[b]=ar[i];
                ar[i]=0; continue;
            }
            if(!ans[c]&&ar[i]){
                ans[c]=ar[i];
                ar[i]=0; continue;
            }
        }
    }for(int i=1;i<=n;print ans[i++]<<' ');
}
/*
*/


#include<bits/stdc++.h>
using namespace std;
#define all(v)            v.begin(),v.end()
#define allR(v)           v.rbegin(),v.rend()
#define V                 vector
#define S                 string
#define pb                push_back
#define pf                push_front
#define set(a,b)          memset(a,b,sizeof(a))
#define mp(a,b)           make_pair(a,b)
#define sz                size()
#define get               cin>>
#define print             cout<<
#define getArr(ar,n)      for(int i=0;i<n;get ar[i++])
#define printArr(ar,n)    for(int i=0;i<n;print ar[i++]<<' ')
#define OO 1e6
#define pii               pair<int,int>
#define Sort(ar,n)        sort(ar,ar+n)
#define getPoint(x,y)     get x>>y
#define dist(x1,y1,x2,y2) (x1-x2)*(x1-x2) + ((y1-y2)*(y1-y2))
#define file              freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define IO                cin.tie(0);std::ios::sync_with_stdio(false);
typedef long long ll;
typedef unsigned long long ull;
typedef double lf;
int dx[] = { 1 , -1 , 0 , 0 };
int dy[] = { 0 , 0 , 1 , -1 };
const ll mod = 1000000007;
const lf pi = 3.1415926536;
int main(){
    IO
    int n,m; get n>>m;
    int ans[n+1]; set(ans,0);
    for(int i=0;i<m;i++){
        int a,b,c; get a>>b>>c;
        int ar[]={1,2,3};
        if(ans[a])ar[ans[a]-1]=0;
        if(ans[b])ar[ans[b]-1]=0;
        if(ans[c])ar[ans[c]-1]=0;
        for(int i=0;i<3;i++){
            if(!ans[a]&&ar[i]){
                ans[a]=ar[i];
                ar[i]=0; continue;
            }
            if(!ans[b]&&ar[i]){
                ans[b]=ar[i];
                ar[i]=0; continue;
            }
            if(!ans[c]&&ar[i]){
                ans[c]=ar[i];
                ar[i]=0; continue;
            }
        }
    }for(int i=1;i<=n;print ans[i++]<<' ');
}
/*
*/


#include<bits/stdc++.h>
using namespace std;
#define all(v)            v.begin(),v.end()
#define allR(v)           v.rbegin(),v.rend()
#define V                 vector
#define S                 string
#define pb                push_back
#define pf                push_front
#define set(a,b)          memset(a,b,sizeof(a))
#define mp(a,b)           make_pair(a,b)
#define sz                size()
#define get               cin>>
#define print             cout<<
#define getArr(ar,n)      for(int i=0;i<n;get ar[i++])
#define printArr(ar,n)    for(int i=0;i<n;print ar[i++]<<' ')
#define OO 1e6
#define pii               pair<int,int>
#define Sort(ar,n)        sort(ar,ar+n)
#define getPoint(x,y)     get x>>y
#define dist(x1,y1,x2,y2) (x1-x2)*(x1-x2) + ((y1-y2)*(y1-y2))
#define file              freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define IO                cin.tie(0);std::ios::sync_with_stdio(false);
typedef long long ll;
typedef unsigned long long ull;
typedef double lf;
int dx[] = { 1 , -1 , 0 , 0 };
int dy[] = { 0 , 0 , 1 , -1 };
const ll mod = 1000000007;
const lf pi = 3.1415926536;
//Again :D
int main(){
    IO
    int n,m; get n>>m;
    int ans[n+1]; set(ans,0);
    for(int i=0;i<m;i++){
        int a,b,c; get a>>b>>c;
        int ar[]={1,2,3};
        if(ans[a])ar[ans[a]-1]=0;
        if(ans[b])ar[ans[b]-1]=0;
        if(ans[c])ar[ans[c]-1]=0;
        for(int i=0;i<3;i++){
            if(!ans[a]&&ar[i]){
                ans[a]=ar[i];
                ar[i]=0; continue;
            }
            if(!ans[b]&&ar[i]){
                ans[b]=ar[i];
                ar[i]=0; continue;
            }
            if(!ans[c]&&ar[i]){
                ans[c]=ar[i];
                ar[i]=0; continue;
            }
        }
    }for(int i=1;i<=n;print ans[i++]<<' ');
}
/*
*/


#include<bits/stdc++.h>
using namespace std;
#define all(v)            v.begin(),v.end()
#define allR(v)           v.rbegin(),v.rend()
#define V                 vector
#define S                 string
#define pb                push_back
#define pf                push_front
#define set(a,b)          memset(a,b,sizeof(a))
#define mp(a,b)           make_pair(a,b)
#define sz                size()
#define get               cin>>
#define print             cout<<
#define getArr(ar,n)      for(int i=0;i<n;get ar[i++])
#define printArr(ar,n)    for(int i=0;i<n;print ar[i++]<<' ')
#define OO 1e6
#define pii               pair<int,int>
#define Sort(ar,n)        sort(ar,ar+n)
#define getPoint(x,y)     get x>>y
#define dist(x1,y1,x2,y2) (x1-x2)*(x1-x2) + ((y1-y2)*(y1-y2))
#define file              freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define IO                cin.tie(0);std::ios::sync_with_stdio(false);
typedef long long ll;
typedef unsigned long long ull;
typedef double lf;
int dx[] = { 1 , -1 , 0 , 0 };
int dy[] = { 0 , 0 , 1 , -1 };
const ll mod = 1000000007;
const lf pi = 3.1415926536;
int main(){
    IO
    int n,m; get n>>m;
    int ans[n+1]; set(ans,0);
    for(int i=0;i<m;i++){
        int a,b,c; get a>>b>>c;
        int ar[]={1,2,3};
        for(int i=0;i<n;i++){
            if(!ans[a]&&ar[i]){
                ans[a]=ar[i];
                ar[i]=0; continue;
            }
            if(!ans[b]&&ar[i]){
                ans[b]=ar[i];
                ar[i]=0; continue;
            }
            if(!ans[c]&&ar[i]){
                ans[c]=ar[i];
                ar[i]=0; continue;
            }
        }
    }for(int i=1;i<=n;print ans[i++]<<' ');
}
/*
*/


#include<bits/stdc++.h>
using namespace std;
#define all(v)            v.begin(),v.end()
#define allR(v)           v.rbegin(),v.rend()
#define V                 vector
#define S                 string
#define pb                push_back
#define pf                push_front
#define set(a,b)          memset(a,b,sizeof(a))
#define mp(a,b)           make_pair(a,b)
#define sz                size()
#define get               cin>>
#define print             cout<<
#define getArr(ar,n)      for(int i=0;i<n;get ar[i++])
#define printArr(ar,n)    for(int i=0;i<n;print ar[i++]<<' ')
#define OO 1e6
#define pii               pair<int,int>
#define Sort(ar,n)        sort(ar,ar+n)
#define getPoint(x,y)     get x>>y
#define dist(x1,y1,x2,y2) (x1-x2)*(x1-x2) + ((y1-y2)*(y1-y2))
#define file              freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define IO                cin.tie(0);std::ios::sync_with_stdio(false);
typedef long long ll;
typedef unsigned long long ull;
typedef double lf;
int dx[] = { 1 , -1 , 0 , 0 };
int dy[] = { 0 , 0 , 1 , -1 };
const ll mod = 1000000007;
const lf pi = 3.1415926536;
//resubmit
int main(){
    IO
    int n,m; get n>>m;
    int ans[n+1]; set(ans,0);
    for(int i=0;i<m;i++){
        int a,b,c; get a>>b>>c;
        int ar[]={1,2,3};
        if(ans[a])ar[ans[a]-1]=0;
        if(ans[b])ar[ans[b]-1]=0;
        if(ans[c])ar[ans[c]-1]=0;
        for(int i=0;i<3;i++){
            if(!ans[a]&&ar[i]){
                ans[a]=ar[i];
                ar[i]=0; continue;
            }
            if(!ans[b]&&ar[i]){
                ans[b]=ar[i];
                ar[i]=0; continue;
            }
            if(!ans[c]&&ar[i]){
                ans[c]=ar[i];
                ar[i]=0; continue;
            }
        }
    }for(int i=1;i<=n;print ans[i++]<<' ');
}
/*
*/


#include<bits/stdc++.h>
using namespace std;
#define all(v)            v.begin(),v.end()
#define allR(v)           v.rbegin(),v.rend()
#define V                 vector
#define S                 string
#define pb                push_back
#define pf                push_front
#define set(a,b)          memset(a,b,sizeof(a))
#define mp(a,b)           make_pair(a,b)
#define sz                size()
#define get               cin>>
#define print             cout<<
#define getArr(ar,n)      for(int i=0;i<n;get ar[i++])
#define printArr(ar,n)    for(int i=0;i<n;print ar[i++]<<' ')
#define OO 1e6
#define pii               pair<int,int>
#define Sort(ar,n)        sort(ar,ar+n)
#define getPoint(x,y)     get x>>y
#define dist(x1,y1,x2,y2) (x1-x2)*(x1-x2) + ((y1-y2)*(y1-y2))
#define file              freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define IO                cin.tie(0);std::ios::sync_with_stdio(false);
typedef long long ll;
typedef unsigned long long ull;
typedef double lf;
int dx[] = { 1 , -1 , 0 , 0 };
int dy[] = { 0 , 0 , 1 , -1 };
const ll mod = 1000000007;
const lf pi = 3.1415926536;
//submit again!
int main(){
    IO
    int n,m; get n>>m;
    int ans[n+1]; set(ans,0);
    for(int i=0;i<m;i++){
        int a,b,c; get a>>b>>c;
        int ar[]={1,2,3};
        if(ans[a])ar[ans[a]-1]=0;
        if(ans[b])ar[ans[b]-1]=0;
        if(ans[c])ar[ans[c]-1]=0;
        for(int i=0;i<3;i++){
            if(!ans[a]&&ar[i]){
                ans[a]=ar[i];
                ar[i]=0; continue;
            }
            if(!ans[b]&&ar[i]){
                ans[b]=ar[i];
                ar[i]=0; continue;
            }
            if(!ans[c]&&ar[i]){
                ans[c]=ar[i];
                ar[i]=0; continue;
            }
        }
    }for(int i=1;i<=n;print ans[i++]<<' ');
}
/*
*/


#include <bits/stdc++.h>
#define N 100010

using namespace std;

int a[N][5], color[N];

void f(int col, int k , int p){
	for(int i = 1; i <= 3; i ++)
		if(i != col)color[k] = i;
	for(int i = 1; i <= 3 ; i ++)
		if(i != color[k] && i != col)color[p] = i;
}
int main() {
	int n, m ,a,b,c;
	cin >> n >> m;
	for(int i = 1; i <= m ; i ++){
		cin >> a >> b >> c;
		if(color[a] + color[b] + color[c] == 0){
			color[a] = 1;
			color[b] = 2;
			color[c] = 3;
		}else {
			if(color[a])f(color[a], b, c);
			if(color[b])f(color[b], a,c);
			if(color[c])f(color[c], a, b);
		}
	}
	for(int i = 1; i <= n ; i ++){
		cout << color[i] << " ";
	}
}


#include <bits/stdc++.h>
#define N 100010

using namespace std;

int a[N][5], color[N];

void f(int col, int k , int p){
	for(int i = 1; i <= 3; i ++)
		if(i != col)color[k] = i;
	for(int i = 1; i <= 3 ; i ++)
		if(i != color[k] && i != col)color[p] = i;
}
int main() {
	int n, m ,a,b,c;
	cin >> n >> m;
	for(int i = 1; i <= m ; i ++){
		cin >> a >> b >> c;
		if(color[a] + color[b] + color[c] == 0){
			color[a] = 1;
			color[b] = 2;
			color[c] = 3;
		}else {
			if(color[a]){f(color[a], b, c);continue;}
			 if(color[b]){f(color[b], a,c);continue;}
			 if(color[c]){f(color[c], a, b);continue;}
		}
	}
	for(int i = 1; i <= n ; i ++){
		cout << color[i] << " ";
	}
}


#include <bits/stdc++.h>
using namespace std;
#define N 100010
int c[N];
bool f[10];

int main(){
    int n, m;
    scanf("%d%d", &n,&m);
    int a;
    for(int j = 0; j < 3; j ++){
        scanf("%d", &a);
        c[a] = j + 1;
    }
    for(int i = 1; i < m; i ++){
        f[1] = 0, f[2] = 0, f[3] = 0;
        for(int j = 0; j < 3; j ++){
            scanf("%d", &a);
            if(c[a] > 0) f[c[a]] = 1;
            else{
                for(int l = 1; l <= 3; l ++){
                    if(f[l] == 1) continue;
                    else {c[a] = l;
                    f[l] = 1;
                    break;
                    }
                }
            }
        }
    }
    for(int i = 1; i < n; i ++) printf("%d ", c[i]);
    printf("%d", c[n]);
}


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

const int N = 1e5 + 10;
int a[N],b[N][3],color[N];

void operation_1(int x,int y,int z){
	color[x] = 1; color[y] = 2; color[z] = 3;
}

void operation_2(int x,int y,int z){
	for(int i = 1; i <= 3; i++)
		if(x != i) {color[y] = i;  break;}
	for(int i = 1; i <= 3; i++)
		if(x != i && color[y] != i)
		{color[z] = i; break;}
}

int main(){
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i = 0; i < m; i++){
		for(int j = 0; j < 3; j++)
			scanf("%d",&b[i][j]);
	}
	for(int i = 0; i < m; i++){
		int x,y,z;
		x = b[i][0]; y = b[i][1]; z = b[i][2];
		if(color[x] == 0 && color[y] == 0 && color[z] == 0)
			operation_1(x,y,z);
		else {
			if(color[x] > 0) operation_2(color[x],y,z);
			else if(color[y] > 0) operation_2(color[y],x,z);
			else if(color[z] > 0) operation_2(color[z],x,y);
		}
	}
	for(int i = 1; i <= n; i++)
		printf("%d ",color[i]);
}


#include <bits/stdc++.h>
#define N 100010

using namespace std;

int a[N][5], color[N];

void f(int col, int k , int p){
	for(int i = 1; i <= 3; i ++)
		if(i != col)color[k] = i;
	for(int i = 1; i <= 3 ; i ++)
		if(i != color[k] && i != col)color[p] = i;
}
int main() {
	int n, m ,a,b,c;
	cin >> n >> m;
	for(int i = 1; i <= m ; i ++){
		cin >> a >> b >> c;
		if(color[a] + color[b] + color[c] == 0){
			color[a] = 1;
			color[b] = 2;
			color[c] = 3;
		}else {
			if(color[a])f(color[a], b, c);
			else if(color[b])f(color[b], a,c);
			else if(color[c])f(color[c], a, b);
		}
	}
	for(int i = 1; i <= n ; i ++){
		cout << color[i] << " ";
	}
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>

using namespace std;
int a[110000][4];
int way[110000];
int pp[110000];
int c[110000];
void work(int x)
{
	pp[x]=1;
	int p[4];
	memset(p,0,sizeof(p));
	for (int i=1;i<=3;i++)
	    p[way[a[x][i]]]=1;
	for (int i=1;i<=3;i++)
	{
		if (way[a[x][i]]!=0) continue;
		for (int j=1;j<=3;j++)
		    if (!p[j])
		    {
				p[j]=1;
				way[a[x][i]]=j;
				break;
			}
	}
	for (int i=1;i<=3;i++)
	{
		if (c[a[x][i]]!=-1&&!pp[c[a[x][i]]]) work(c[a[x][i]]);
	}
}
int main()
{
    int n,m;
	cin>>n>>m;
	for (int i=1;i<=m;i++)
	{
		cin>>a[i][1]>>a[i][2]>>a[i][3];
		for (int j=1;j<=n;j++)
		    if (c[a[i][j]]==0) c[a[i][j]]=-1;
		             else   c[a[i][j]]=i;
	}
    for (int i=1;i<=m;i++)
    {
		if (!pp[i]) work(i);
	}
	for (int i=1;i<=n;i++)
	    if (way[i]==0) way[i]=1;
	for (int i=1;i<=n;i++)
	    printf("%d%c",way[i],i==n?'\n':' ');
	return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>

using namespace std;
int a[110000][4];
int way[110000];
int pp[110000];
int c[110000];
void work(int x)
{
	pp[x]=1;
	int p[4];
	memset(p,0,sizeof(p));
	for (int i=1;i<=3;i++)
	    p[way[a[x][i]]]=1;
	for (int i=1;i<=3;i++)
	{
		if (way[a[x][i]]!=0) continue;
		for (int j=1;j<=3;j++)
		    if (!p[j])
		    {
				p[j]=1;
				way[a[x][i]]=j;
				break;
			}
	}
	for (int i=1;i<=3;i++)
	{
		if (c[a[x][i]]!=-1&&!pp[c[a[x][i]]]) work(c[a[x][i]]);
	}
}
int main()
{
    int n,m;
	scanf("%d %d",&n,&m);
	for (int i=1;i<=m;i++)
	{
		scanf("%d %d %d",&a[i][1],&a[i][2],&a[i][3]);
		for (int j=1;j<=n;j++)
		    if (c[a[i][j]]==0) c[a[i][j]]=-1;
		             else   c[a[i][j]]=i;
	}
    for (int i=1;i<=m;i++)
    {
		if (!pp[i]) work(i);
	}
	for (int i=1;i<=n;i++)
	    if (way[i]==0) way[i]=1;
	for (int i=1;i<=n;i++)
	    printf("%d%c",way[i],i==n?'\n':' ');
	return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>

using namespace std;
int a[110000][4];
int way[110000];
int pp[110000];
int c[110000];
void work(int x)
{
	pp[x]=1;
	int p[4];
	memset(p,0,sizeof(p));
	for (int i=1;i<=3;i++)
	    p[way[a[x][i]]]=1;
	for (int i=1;i<=3;i++)
	{
		if (way[a[x][i]]!=0) continue;
		for (int j=1;j<=3;j++)
		    if (!p[j])
		    {
				p[j]=1;
				way[a[x][i]]=j;
				break;
			}
	}
	for (int i=1;i<=3;i++)
	{
		if (c[a[x][i]]!=-1&&!pp[c[a[x][i]]]) work(c[a[x][i]]);
	}
}
int main()
{
    int n,m;
	scanf("%d %d",&n,&m);
	for (int i=1;i<=m;i++)
	{
		scanf("%d %d %d",&a[i][1],&a[i][2],&a[i][3]);
		for (int j=1;j<=3;j++)
		    if (c[a[i][j]]==0) c[a[i][j]]=-1;
		             else   c[a[i][j]]=i;
	}
    for (int i=1;i<=m;i++)
    {
		if (!pp[i]) work(i);
	}
	for (int i=1;i<=n;i++)
	    if (way[i]==0) way[i]=1;
	for (int i=1;i<=n;i++)
	    printf("%d%c",way[i],i==n?'\n':' ');
	return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <memory.h>
using namespace std;
int col[100010] , a , b ;
void coloring(int x ){
    if(x==1){
         a = 2;
         b = 3;
         return;
    }
    if(x==2){
        a = 1;
        b = 3;
        return ;
    }
    a = 1;
    b = 2;
}
int main() {
	// your code goes here
	int n , x ,y , z ,m;
	cin >> n >> m;
	for(int i = 0;i<0;i++){
	    cin >> x >> y >> z;
	    if (col[x]== 0 && col[y]==0&&col[z]==0){
	        col[x]=1;col[y]=2;col[z]=3;
	    }else if(col[x] !=0){
	        coloring(col[x]);
	        col[y]=a;
	        col[z]=b;
	    }else if(col[b] !=0){
	        coloring(col[b]);
	        col[x]=a;
	        col[z]=b;
	    }else if(col[z] !=0){
	        coloring(col[z]);
	        col[x]=a;
	        col[y]=b;
	    }
	}
	for(int i = 1;i <= n ; i++){
	    cout << col[i] << " ";
	}

	return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <memory.h>
using namespace std;
int col[100010] , a , b ;
void coloring(int x ){
    if(x==1){
         a = 2;
         b = 3;
         return;
    }
    if(x==2){
        a = 1;
        b = 3;
        return ;
    }
    a = 1;
    b = 2;
}
int main() {
	// your code goes here
	int n , x ,y , z ,m;
	cin >> n >> m;
	for(int i = 0;i<m;i++){
	    cin >> x >> y >> z;

	    if (col[x]== 0 && col[y]==0&&col[z]==0){
	        col[x]=1;col[y]=2;col[z]=3;
	    }else if(col[x] !=0){
	        coloring(col[x]);
	        col[y]=a;
	        col[z]=b;
	    }else if(col[y] !=0){
	        coloring(col[y]);
	        col[x]=a;
	        col[z]=b;
	    }else if(col[z] !=0){
	        coloring(col[z]);
	        col[x]=a;
	        col[y]=b;
	    }
	}
	for(int i = 1;i <= n ; i++){
	    cout << col[i] << " ";
	}

	return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <memory.h>
using namespace std;
int col[N] , a , b ;
void coloring(int x ){
    if(x==1){
         a = 2;
         b = 3;
         return;
    }
    if(x==2){
        a = 1;
        b = 3;
        return ;
    }
    a = 1;
    b = 2;
}
int main() {
	// your code goes here
	int n , x ,y , z ,m;
	cin >> n >> m;
	for(int i = 0;i<0;i++){
	    cin >> x >> y >> z;
	    if (col[x]== 0 && col[y]==0&&col[z]==0){
	        col[x]=1;col[y]=2;col[z]=3;
	    }else if(col[x] !=0){
	        coloring(col[x]);
	        col[y]=a;
	        col[z]=b;
	    }else if(col[b] !=0){
	        coloring(col[b]);
	        col[x]=a;
	        col[z]=b;
	    }else if(col[z] !=0){
	        coloring(col[z]);
	        col[x]=a;
	        col[y]=b;
	    }
	}
	for(int i = 1;i <= n ; i++){
	    cout << col[i] << " ";
	}

	return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <memory.h>
using namespace std;
int col[100010] , a , b ;
void coloring(int x ){
    if(x==1){
         a = 2;
         b = 3:
         return;
    }
    if(x==2){
        a = 1;
        b = 3;
        return ;
    }
    a = 1;
    b = 2;
}
int main() {
	// your code goes here
	int n , x ,y , z ,m;
	cin >> n >> m;
	for(int i = 0;i<0;i++){
	    cin >> x >> y >> z;
	    if (col[x]== 0 && col[y]==0&&col[z]==0){
	        col[x]=1;col[y]=2;col[z]=3;
	    }else if(col[x] !=0){
	        coloring(col[x]);
	        col[y]=a;
	        col[z]=b;
	    }else if(col[b] !=0){
	        coloring(col[b]);
	        col[x]=a;
	        col[z]=b;
	    }else if(col[z] !=0){
	        coloring(col[z]);
	        col[x]=a;
	        col[y]=b;
	    }
	}
	for(int i = 1;i <= n ; i++){
	    cout << col[i] << " ";
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct Node{
int x,y;
bool operator<(const Node&a)const {
   if(x!=a.x) return x<a.x;
   else y<a.y;
}
}node[105];
int main(){
int n,m;
while(cin>>n>>m){
    for(int i=0;i<n;i++){
    cin>>node[i].x>>node[i].y;
    //node[i].y+=node[i].x;
    }
    sort(node,node+n);
    int x=1;
    int cnt=0;
    int ans[105];
    int p=0;
    while(node[0].x>x)ans[cnt++]=x++;
 for(int i=1;i<n;i++){

    if(node[i].x>node[i-1].y+1){

        int temp=node[i].x;
        int temp2=node[i-1].y+1;

        while(temp2<temp){
            ans[cnt++]=temp2++;
        }
    }
 }

 while(node[n-1].y+1<m)ans[cnt++]=node[n-1].y+++1;
    cout<<cnt<<endl;
    if(cnt){
        cout<<ans[0];
        for(int i=1;i<cnt;i++)printf(" %d",ans[i]);
        cout<<endl;
    }

}
return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct Node{
int x,y;
bool operator<(const Node&a)const {
   if(x!=a.x) return x<a.x;
   else y<a.y;
}
}node[105];
int main(){
int n,m;
while(cin>>n>>m){
    for(int i=0;i<n;i++){
    cin>>node[i].x>>node[i].y;
    //node[i].y+=node[i].x;
    }
    sort(node,node+n);
    int x=1;
    int cnt=0;
    int ans[105];
    int p=0;
    while(node[0].x>x)ans[cnt++]=x++;
    int xx=node[0].y;

 for(int i=1;i<n;i++){
while(node[i].x==node[i-1].x&&i<n)i++;
    if(node[i].x>node[i-1].y+1){

        int temp=node[i].x;
        int temp2=node[i-1].y+1;

        while(temp2<temp){
            ans[cnt++]=temp2++;
        }
    }
 }

 while(node[n-1].y+1<=m)ans[cnt++]=++node[n-1].y;
    cout<<cnt<<endl;
    if(cnt){
        cout<<ans[0];
        for(int i=1;i<cnt;i++)printf(" %d",ans[i]);
        cout<<endl;
    }

}
return 0;
}


/*
1014A
*/
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <vector>

using namespace std;

#define long long long
#define foe(i , v) for(__typeof(v.begin()) i = v.begin() ; i != v.end(); i++)
#define fi first
#define se second
#define pb push_back
#define fio ios_base::sync_with_stdio(false); cin.tie(0)
#define task "test"
#define ini freopen(task".inp","r",stdin); freopen(task".out","w",stdout)
#define fo(i , a , b) for(int i = a ; i <= b ; i ++)
#define fu(i , a , b) for(int i = a ; i >= b ; i --)
#define db(a) cout << a << ' '
#define de(a) cout << a << endl

typedef vector <int> vi;
typedef pair <long , long> pll;
typedef vector <pll > vll;
typedef unsigned long ull;

const int N = (int) 1e6 + 4;
const int dx[] = {-1 , 0 , 1 , 0};
const int dy[] = {0 , -1 , 0 , 1};

struct segment {
    int x , y;
};

int n , m  , b[N];
segment a[N];

void init() {
    //ini;
    fio;
    cin >> n >> m;
    fo(i , 1 , n) {
        cin >> a[i].x;
        cin >> a[i].y;
        fo(j , a[i].x , a[i].y) b[j] = j;
    }
}

vector <int> v;

void solve() {
    fo(i , 1 , m) {
        if (b[i] == 0) v.pb(i);
    }
    cout << v.size() << endl;
    foe(i , v) cout << *i << ' ' ;
}

int main () {
    init();
    solve();
    return 0;
}


/*
1014A
*/
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <vector>

using namespace std;

#define long long long
#define foe(i , v) for(__typeof(v.begin()) i = v.begin() ; i != v.end(); i++)
#define fi first
#define se second
#define pb push_back
#define fio ios_base::sync_with_stdio(false); cin.tie(0)
#define task "test"
#define ini freopen(task".inp","r",stdin); freopen(task".out","w",stdout)
#define fo(i , a , b) for(int i = a ; i <= b ; i ++)
#define fu(i , a , b) for(int i = a ; i >= b ; i --)
#define db(a) cout << a << ' '
#define de(a) cout << a << endl

typedef vector <int> vi;
typedef pair <long , long> pll;
typedef vector <pll > vll;
typedef unsigned long ull;

const int N = (int) 1e6 + 4;
const int dx[] = {-1 , 0 , 1 , 0};
const int dy[] = {0 , -1 , 0 , 1};

struct segment{
    int x , y;
};

segment a[N];
int n , m;

bool cmp (segment a , segment b) {
    return a.x < b.x;
}
void init() {
    //ini;
    fio;
    cin >> n >> m;
    fo(i , 1 , n) {
        cin >> a[i].x;
        cin >> a[i].y;
    }
    n++;
    a[n].x = m;
    a[n].y = 0;
    sort(a + 1 , a + 1 + n , cmp);
}

vector <int> v;

void solve() {
    //fo(i , 1 , n) db(a[i].x) , db(a[i].y) , de("");
    fo(i , 1 , a[1].x - 1) v.push_back(i);
    int findmax = a[1].y;
    fo(i , 2 , n) {
        if (findmax < a[i - 1].y) findmax = a[i - 1].y;
        fo(j , findmax + 1 , a[i].x - 1) v.pb(j);
    }
    cout << v.size() << endl;
    foe(i , v) cout << *i << ' ';
}

int main () {
    init();
    solve();
    return 0;
}


/*
1014A
*/
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <vector>

using namespace std;

#define long long long
#define foe(i , v) for(__typeof(v.begin()) i = v.begin() ; i != v.end(); i++)
#define fi first
#define se second
#define pb push_back
#define fio ios_base::sync_with_stdio(false); cin.tie(0)
#define task "test"
#define ini freopen(task".inp","r",stdin); freopen(task".out","w",stdout)
#define fo(i , a , b) for(int i = a ; i <= b ; i ++)
#define fu(i , a , b) for(int i = a ; i >= b ; i --)
#define db(a) cout << a << ' '
#define de(a) cout << a << endl

typedef vector <int> vi;
typedef pair <long , long> pll;
typedef vector <pll > vll;
typedef unsigned long ull;

const int N = (int) 1e6 + 4;
const int dx[] = {-1 , 0 , 1 , 0};
const int dy[] = {0 , -1 , 0 , 1};

struct segment{
    int x , y;
};

segment a[N];
int n , m , tmin = INT_MAX;

bool cmp (segment a , segment b) {
    return a.y < b.y;
}
void init() {
    //ini;
    fio;
    cin >> n >> m;
    fo(i , 1 , n) {
        cin >> a[i].x;
        cin >> a[i].y;
        if (tmin > a[i].x) tmin = a[i].x;
    }
    n++;
    a[n].y = m;
    a[n].x = m;
    sort(a + 1 , a + 1 + n , cmp);
}

vector <int> v;

void solve() {
    //fo(i , 1 , n) db(a[i].x) , db(a[i].y) , de("");
    fo(i , 1 , tmin - 1) v.push_back(i);
    fo(i , 2 , n) {
        fo(j , a[i - 1].y + 1 , a[i].x - 1) v.pb(j);
    }
    cout << v.size() << endl;
    foe(i , v) cout << *i << ' ';
}

int main () {
    init();
    solve();
    return 0;
}


/*

*/
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <vector>

using namespace std;

#define long long long
#define foe(i , v) for(__typeof(v.begin()) i = v.begin() ; i != v.end(); i++)
#define fi first
#define se second
#define pb push_back
#define fio ios_base::sync_with_stdio(false); cin.tie(0)
#define task "test"
#define ini freopen(task".inp","r",stdin); freopen(task".out","w",stdout)
#define fo(i , a , b) for(int i = a ; i <= b ; i ++)
#define fu(i , a , b) for(int i = a ; i >= b ; i --)
#define db(a) cout << a << ' '
#define de(a) cout << a << endl

typedef vector <int> vi;
typedef pair <long , long> pll;
typedef vector <pll > vll;
typedef unsigned long ull;

const int N = (int) 1e6 + 4;
const int dx[] = {-1 , 0 , 1 , 0};
const int dy[] = {0 , -1 , 0 , 1};

struct segment{
    int x , y;
};

segment a[N];
int n , m;

bool cmp (segment a , segment b) {
    return a.x < b.x;
}
void init() {
    //ini;
    fio;
    cin >> n >> m;
    fo(i , 1 , n) {
        cin >> a[i].x;
        cin >> a[i].y;
    }
    sort(a + 1 , a + 1 + n , cmp);
}

vector <int> v;

void solve() {
    //fo(i , 1 , n) cout << a[i].x << ' ' << a[i].y << endl;
    fo(i , 1 , a[1].x - 1) v.push_back(i);
    fo(i , 2 , n) {
        fo(j , a[i - 1].y + 1 , a[i].x - 1) v.pb(j);
    }
    cout << v.size() << endl;
    foe(i , v) cout << *i << ' ';
}

int main () {
    init();
    solve();
    return 0;
}


/*
1014A
*/
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <vector>

using namespace std;

#define long long long
#define foe(i , v) for(__typeof(v.begin()) i = v.begin() ; i != v.end(); i++)
#define fi first
#define se second
#define pb push_back
#define fio ios_base::sync_with_stdio(false); cin.tie(0)
#define task "test"
#define ini freopen(task".inp","r",stdin); freopen(task".out","w",stdout)
#define fo(i , a , b) for(int i = a ; i <= b ; i ++)
#define fu(i , a , b) for(int i = a ; i >= b ; i --)
#define db(a) cout << a << ' '
#define de(a) cout << a << endl

typedef vector <int> vi;
typedef pair <long , long> pll;
typedef vector <pll > vll;
typedef unsigned long ull;

const int N = (int) 1e6 + 4;
const int dx[] = {-1 , 0 , 1 , 0};
const int dy[] = {0 , -1 , 0 , 1};

struct segment{
    int x , y;
};

segment a[N];
int n , m;

bool cmp (segment a , segment b) {
    return a.x < b.x;
}
void init() {
    //ini;
    fio;
    cin >> n >> m;
    fo(i , 1 , n) {
        cin >> a[i].x;
        cin >> a[i].y;
    }
    sort(a + 1 , a + 1 + n , cmp);
}

vector <int> v;

void solve() {
    //fo(i , 1 , n) cout << a[i].x << ' ' << a[i].y << endl;
    fo(i , 1 , a[1].x - 1) v.push_back(i);
    fo(i , 2 , n) {
        fo(j , a[i - 1].y + 1 , a[i].x - 1) v.pb(j);
    }
    fo(i , a[n].y + 1 , m) v.pb(i);
    cout << v.size() << endl;
    foe(i , v) cout << *i << ' ';
}

int main () {
    init();
    solve();
    return 0;
}


/*
1014A
*/
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <vector>

using namespace std;

#define long long long
#define foe(i , v) for(__typeof(v.begin()) i = v.begin() ; i != v.end(); i++)
#define fi first
#define se second
#define pb push_back
#define fio ios_base::sync_with_stdio(false); cin.tie(0)
#define task "test"
#define ini freopen(task".inp","r",stdin); freopen(task".out","w",stdout)
#define fo(i , a , b) for(int i = a ; i <= b ; i ++)
#define fu(i , a , b) for(int i = a ; i >= b ; i --)
#define db(a) cout << a << ' '
#define de(a) cout << a << endl

typedef vector <int> vi;
typedef pair <long , long> pll;
typedef vector <pll > vll;
typedef unsigned long ull;

const int N = (int) 1e6 + 4;
const int dx[] = {-1 , 0 , 1 , 0};
const int dy[] = {0 , -1 , 0 , 1};

struct segment{
    int x , y;
};

segment a[N];
int n , m;

bool cmp (segment a , segment b) {
    return a.x < b.x;
}
void init() {
    //ini;
    fio;
    cin >> n >> m;
    fo(i , 1 , n) {
        cin >> a[i].x;
        cin >> a[i].y;
    }
    n++;
    a[n].x = m;
    a[n].y = 0;
    sort(a + 1 , a + 1 + n , cmp);
}

vector <int> v;

void solve() {
    fo(i , 1 , n) db(a[i].x) , db(a[i].y) , de("");
    fo(i , 1 , a[1].x - 1) v.push_back(i);
    int findmax = a[1].y;
    fo(i , 2 , n) {
        if (findmax < a[i - 1].y) findmax = a[i - 1].y;
        fo(j , findmax + 1 , a[i].x - 1) v.pb(j);
    }
    cout << v.size() << endl;
    foe(i , v) cout << *i << ' ';
}

int main () {
    init();
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int arr[102] = { 0 };
int main() {
	int n, max;
	cin >> n >> max;
	for (int i = 0; i < n; ++i) {
		int l, r;
		cin >> l >> r;
		for (int i = l; i <= r; ++i) {
			arr[i] = 1;
		}
	}
	int cnt = 0;
	if (arr[1] == 0) {
		cnt = 1;
	}
	for (int i = 1; i <= max; ++i) {
		if (arr[i] == 0) {
			++cnt;
		}
	}
	cout << cnt << endl;
	if (arr[1] == 0) {
		cout << 1 << " ";
	}
	for (int i = 2; i < max; ++i) {
		if (arr[i] == 0 && arr[i + 1] == 1) {
			cout << i << endl;
		}
		if (arr[i - 1] == 1 && arr[i] == 0) {
			cout << i << " ";
		}
	}
	if (arr[max] == 0) {
		cout << max << endl;
	}
}


#include<bits\stdc++.h>
using namespace std;
int a[105];
int main() {
	int n, m;
	cin >> n >> m;
	m += 1;
	for (int i = 0; i < n; ++i) {
		int l, r;
		cin >> l >> r;
		for (int j = l; j <= r; ++j) {
			a[j] = 1;
		}
	}
	int cnt = 0;
	for (int i = 1; i < m; ++i) {
		if (a[i] == 0) {
			cnt++;
		}
	}
	cout << cnt << endl;
	for (int i = 1; i < m; ++i) {
		if (a[i] == 0) {
			cout << i << " ";
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
int arr[102] = { 0 };
int main() {
	int n, max;
	cin >> n >> max;
	for (int i = 0; i < n; ++i) {
		int l, r;
		cin >> l >> r;
		for (int i = l; i <= r; ++i) {
			arr[i] = 1;
		}
	}
	int cnt = 0;
	if (arr[1] == 0) {
		cnt = 1;
	}
	for (int i = 1; i <= max; ++i) {
		if (arr[i] == 0) {
			++cnt;
		}
	}
	cout << cnt << endl;
	for (int i = 1; i <= max; ++i) {
		if (arr[i] == 0) {
			cout << i << (i == max ? '\n' : ' ');
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
int arr[102] = { 0 };
int main() {
	int n, max;
	cin >> n >> max;
	for (int i = 0; i < n; ++i) {
		int l, r;
		cin >> l >> r;
		for (int i = l; i <= r; ++i) {
			arr[i] = 1;
		}
	}
	int cnt = 0;
	for (int i = 1; i <= max; ++i) {
		if (arr[i] == 0) {
			++cnt;
		}
	}
	cout << cnt << endl;
	for (int i = 1; i <= max; ++i) {
		if (arr[i] == 0) {
			cout << i << (i == max ? '\n' : ' ');
		}
	}
}


#include <iostream>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    int l[n], r[n];
    char occupied[m + 1];
    for (int i = 0; i < m; i++)
    {
        occupied[i] == '-';
    }
    for (int i = 0; i < n; i++)
    {
        cin >> l[i] >> r[i];
    }

    for (int i = 0; i < n; i++)
    {
        for (int j = l[i] - 1; j <= r[i] - 1; j++)
        {
            occupied[j] = '#';
        }
    }
    int count = 0;
    for (int i = 0; i < m; i++)
    {
        if (occupied[i] == '#')
            count++;
    }
    cout << m - count << "\n";
    if (m - count == 0)
        return 0;
    for (int i = 0; i < m; i++)
    {
        if (occupied[i] != '#')
            cout << i + 1 << " ";
    }

    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    int l[n], r[n];
    char occupied[m];
    for (int i = 0; i < m; i++)
    {
        occupied[i] == '-';
    }
    for (int i = 0; i < n; i++)
    {
        cin >> l[i] >> r[i];
    }

    for (int i = 0; i < n; i++)
    {
        for (int j = l[i] - 1; j <= r[i] - 1; j++)
        {
            occupied[j] = '#';
        }
    }
    int count = 0;
    for (int i = 0; i < m; i++)
    {
        if (occupied[i] == '#')
            count++;
    }
    cout << m - count << "\n";
    if (m - count == 0)
        return 0;
    for (int i = 0; i < m; i++)
    {
        if (occupied[i] != '#')
            cout << i + 1 << " ";
    }

    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    int l[n], r[n];
    char occupied[m + 1];
    for (int i = 0; i < m; i++)
    {
        occupied[i] == '-';
    }
    for (int i = 0; i < n; i++)
    {
        cin >> l[i] >> r[i];
    }

    for (int i = 0; i < n; i++)
    {
        for (int j = l[i]; j <= r[i]; j++)
        {
            occupied[j - 1] = '#';
        }
    }
    int count = 0;
    for (int i = 0; i < m; i++)
    {
        if (occupied[i] == '#')
            count++;
    }
    cout << m - count << "\n";
    if (m - count == 0)
        return 0;
    for (int i = 0; i < m; i++)
    {
        if (occupied[i] != '#')
            cout << i + 1 << " ";
    }

    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    int l[n], r[n];
    char occupied[m];
    for (int i = 0; i < m + 1; i++)
    {
        occupied[i] == '-';
    }
    for (int i = 0; i < n; i++)
    {
        cin >> l[i] >> r[i];
    }

    for (int i = 0; i < n; i++)
    {
        for (int j = l[i] - 1; j <= r[i] - 1; j++)
        {
            occupied[j] = '#';
        }
    }
    int count = 0;
    for (int i = 0; i < m; i++)
    {
        if (occupied[i] == '#')
            count++;
    }
    cout << m - count << "\n";
    if (m - count == 0)
        return 0;
    for (int i = 0; i < m; i++)
    {
        if (occupied[i] != '#')
            cout << i + 1 << " ";
    }

    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    int l[n], r[n];
    char occupied[m];
    for (int i = 0; i < m; i++)
    {
        occupied[i] = '-';
    }
    for (int i = 0; i < n; i++)
    {
        cin >> l[i] >> r[i];
    }

    for (int i = 0; i < n; i++)
    {
        for (int j = l[i]; j <= r[i]; j++)
        {

            occupied[j - 1] = '#';
        }
    }
    int count = 0;
    for (int i = 0; i < m; i++)
    {
        if (occupied[i] == '#')
            count++;
    }
    cout << m - count << "\n";
    if (m - count == 0)
        return 0;
    for (int i = 0; i < m; i++)
    {
        if (occupied[i] != '#')
            cout << i + 1 << " ";
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
 int n,m,x,y;
 cin>>n>>m;
 bool v[m+2];
 for(int i=0;i<n;i++){
    cin>>x>>y;
    for(int is=x;is<=y;is++){
        v[is]=1;
    }

 }
   int xe=0;
   vector<int> vs;
   for(int is=1;is<=m;is++){
            if(v[is]==0)
                vs.push_back(is);
    }

        cout<< vs.size()<<endl ;
        for(int is=0;is<vs.size();is++){
             cout<<vs[is]<<" ";

       }
       cout<<endl;

return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
 int n,m,x,y;
 cin>>n>>m;
 bool v[m+2]={0};
 for(int i=0;i<n;i++){
    cin>>x>>y;
    for(int is=x;is<=y;is++){
        v[is]=1;
    }

 }
   int xe=0;
   vector<int> vs;
   for(int is=1;is<=m;is++){
            if(v[is]==0)
                vs.push_back(is);
    }

        cout<< vs.size()<<endl ;
        for(int is=0;is<vs.size();is++){
             cout<<vs[is]<<" ";

       }
       cout<<endl;

return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
 int n,m,x,y;
 cin>>n>>m;
 bool v[m];
 for(int i=0;i<n;i++){
    cin>>x>>y;
    for(int is=x-1;is<y;is++){
        v[is]=true;
    }

 }
   int xe=0;
   for(int is=0;is<m;is++){
            if(v[is]==false)
                xe++;
    }
    if(xe==0)cout<<0<<endl;
    else{
        cout<< xe<<endl ;
        for(int is=0;is<m;is++){
            if(v[is]==false){

             cout<<is+1<<" ";
            }
       }
       cout<<endl;
    }
return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
 int n,m,x,y;
 cin>>n>>m;
 int v[m];
 for(int i=0;i<n;i++){
    cin>>x>>y;
    for(int is=x-1;is<y;is++){
        v[is]=1;
    }

 }
   int xe=0;
   for(int is=0;is<m;is++){
            if(v[is]!=1)
                xe++;
    }
    if(xe==0)cout<<0<<endl;
    else{
        cout<< xe<<endl ;
        for(int is=0;is<m;is++){
            if(v[is]!=1){

             cout<<is+1<<" ";
            }
       }
       cout<<endl;
    }
return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
 int n,m,x,y;
 cin>>n>>m;
 bool v[m];
 for(int i=0;i<n;i++){
    cin>>x>>y;
    for(int is=x-1;is<y;is++){
        v[is]=true;
    }

 }
   int xe=0;
   for(int is=0;is<m;is++){
            if(v[is]==false)
                xe++;
    }
    if(xe==0)cout<<0<<endl;
    else{
            int cont=0;
        cout<< xe<<endl ;
        for(int is=0;is<m;is++){
            if(v[is]==false){
                cont++;
                if(cont==1){

             cout<<is+1;
                }else
             cout<<" "<<is+1;
            }
       }
       cout<<endl;
    }
return 0;
}


#include <iostream>
#include <vector>
#include <utility>
using namespace std;
int main(){
    int n, m; cin >> n >> m;
    pair<int, int> a[n];
    vector<int> ans;
    int i = -1;
    while (cin >> a[++i].first >> a[i].second);
    for (int i = 1; i <= m; i++)
    {
        bool in = false;
        for (auto p : a)
        {
            if (i <= p.second || i >= p.first)
            {
                in = true;
                break;
            }
        }
        if (!in) ans.push_back(i);
    }
    cout << ans.size() << endl;
    for (auto n : ans)
    {
        cout << n << " ";
    }
}


#include <iostream>
#include <vector>
#include <utility>
using namespace std;
int main(){
    int n, m; cin >> n >> m;
    pair<int, int> a[n];
    vector<int> ans;
    int i = -1;
    while (cin >> a[++i].first) cin >> >> a[i].second;
    for (int i = 1; i <= m; i++)
    {
        bool in = false;
        for (auto p : a)
        {
            if (i <= p.second || i >= p.first)
            {
                in = true;
                break;
            }
        }
        if (!in) ans.push_back(i);
    }
    cout << ans.size() << endl;
    for (auto n : ans)
    {
        cout << n << " ";
    }
}


#include <iostream>
#include <vector>
#include <utility>
using namespace std;
int main(){
    int n, m; cin >> n >> m;
    pair<int, int> a[n];
    vector<int> ans;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i].first >> a[i].second;
    }
    for (int i = 1; i <= m; i++)
    {
        bool in = false;
        for (auto p : a)
        {
            if (i <= p.second && i >= p.first)
            {
                in = true;
                break;
            }
        }
        if (!in) ans.push_back(i);
    }
    cout << ans.size() << endl;
    for (auto n : ans)
    {
        cout << n << " ";
    }
}


#include <iostream>
#include <vector>
#include <utility>
using namespace std;
int main(){
    int n, m; cin >> n >> m;
    pair<int, int> a[n];
    vector<int> ans;
    int i = -1;
    while (cin >> a[++i].first >> a[i].second);
    for (int i = 1; i <= m; i++)
    {
        for (auto p : a)
        {
            if (i > p.second || i < p.first) ans.push_back(i);
        }
    }
    cout << ans.size() << endl;
    for (auto n : ans)
    {
        cout << n << " ";
    }
}


#include <iostream>
#include <vector>
#include <utility>
using namespace std;
int main(){
    int n, m; cin >> n >> m;
    pair<int, int> a[n];
    vector<int> ans;
    int i = -1;
    while (cin >> a[++i].first >> a[i].second);
    for (int i = 1; i <= m; i++)
    {
        for (auto p : a)
        {
            if (i > a.second || i < a.first) ans.push_back(i);
        }
    }
    cout << ans.size() << endl;
    for (auto n : ans)
    {
        cout << n << " ";
    }
}


#include <iostream>
#include <vector>
#include <utility>
using namespace std;
int main(){
    int n, m; cin >> n >> m;
    pair<int, int> a[n];
    vector<int> ans;
    int i = -1;
    while (cin >> a[++i].first) cin >> a[i].second;
    for (int i = 1; i <= m; i++)
    {
        bool in = false;
        for (auto p : a)
        {
            if (i <= p.second || i >= p.first)
            {
                in = true;
                break;
            }
        }
        if (!in) ans.push_back(i);
    }
    cout << ans.size() << endl;
    for (auto n : ans)
    {
        cout << n << " ";
    }
}


#include <iostream>
#include <vector>
#include <utility>
using namespace std;
int main(){
    int n, m; cin >> n >> m;
    pair<int, int> a[n];
    vector<int> ans;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i].first >> a[i].second;
    }
    for (int i = 1; i <= m; i++)
    {
        bool in = false;
        for (auto p : a)
        {
            if (i <= p.second || i >= p.first)
            {
                in = true;
                break;
            }
        }
        if (!in) ans.push_back(i);
    }
    cout << ans.size() << endl;
    for (auto n : ans)
    {
        cout << n << " ";
    }
}


#include <stdio.h>
#include <string.h>

int main()
{
	short n,m,l,r,a[101];

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

	memset(a,0,100);

	while(n--)
	{
		scanf("%hd%hd",&l,&r);

		if(l == r)
		{
			continue;
		}

		for(;l <= r;l++)
		{
			a[l] = 1;
		}
	}

	r = 0;

	for(l = 1;l < m;l++)
	{
		if(0 == a[l])
		{
			r++;
		}
	}

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

	for(l = 1;l < m;l++)
	{
		if(0 == a[l])
		{
			printf("%d ",l);
		}
	}

	return 0;
}


#include <stdio.h>
#include <string.h>

int main()
{
	short n,m,l,r,a[101];

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

	memset(a,0,101);

	while(n--)
	{
		scanf("%hd%hd",&l,&r);

		if(l == r)
		{
			continue;
		}

		for(;l <= r;l++)
		{
			a[l] = 1;
		}
	}

	r = 0;

	for(l = 1;l <= m;l++)
	{
		if(0 == a[l])
		{
			r++;
		}
	}

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

	for(l = 1;l <= m;l++)
	{
		if(0 == a[l])
		{
			printf("%d ",l);
		}
	}

	return 0;
}


#include <stdio.h>
#include <string.h>

int main()
{
	short n,m,l,r,a[101];

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

	memset(a,0,101);

	while(n--)
	{
		scanf("%hd%hd",&l,&r);

		if(l == r)
		{
			continue;
		}

		for(;l <= r;l++)
		{
			a[l] = 1;
		}
	}

	r = 0;

	for(l = 1;l < m;l++)
	{
		if(0 == a[l])
		{
			r++;
		}
	}

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

	for(l = 1;l < m;l++)
	{
		if(0 == a[l])
		{
			printf("%d ",l);
		}
	}

	return 0;
}


#include<bits/stdc++.h>
#define FASTER ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(int i=a; i<=b; i++)
#define repp(i,a,b) for(int i=a; i>=b; i--)
#define nrep(i,a,b,c) for(int i=a; i<=b; i+=c)
#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define endl '\n'
#define Endl '\n'
#define ld long double
#define mp(x, y) make_pair(x, y)

const double pi=acos(-1.0);
const char digit[]={'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};

using namespace std;
	int n, m;
	int l, r, f[101]={};
int main(){
	// #ifndef ONLINE_JUDGE
	//      freopen("input.txt", "r", stdin);
	//      freopen("output.txt", "w", stdout);
	// #endif
	cin>>n>>m;
	rep (i, 0, n-1){
		cin>>l>>r;
		rep (j, l, r) f[j]=1;
	}
	// rep (i, 1, m) cout<<i<<" "<<f[i]<<endl;
	vector<int> v;
	int c;
	int kiri, kanan;
	rep (i, 1, m){
		// if (f[i]==0){
		// 	kiri=i;
		// 	rep (j, i+1, m){
		// 		if (f[j]==0){
		// 			kanan=j;
		// 			f[j]=1;
		// 		}else{
		// 			break;
		// 		}
		// 	}
		// 	v.pb(make_pair(kiri, kanan));
		// }
		if (f[i]==0) v.pb(i);
	}
	if (v.size()==0){
		cout<<0<<endl;
		return 0;
	}
	cout<<v.size()<<endl;
	rep (i, 0, v.size()-1){
		if (i>0) cout<<" ";
		cout<<v[i];
	}
	cout<<endl;
	return 0;
}


#include<bits/stdc++.h>
#define FASTER ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(int i=a; i<=b; i++)
#define repp(i,a,b) for(int i=a; i>=b; i--)
#define nrep(i,a,b,c) for(int i=a; i<=b; i+=c)
#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define endl '\n'
#define Endl '\n'
#define ld long double
#define mp(x, y) make_pair(x, y)

const double pi=acos(-1.0);
const char digit[]={'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};

using namespace std;
	int n, m;
	int l, r, f[101]={};
int main(){
	#ifndef ONLINE_JUDGE
	    freopen("input.txt", "r", stdin);
	    freopen("output.txt", "w", stdout);
	#endif
	cin>>n>>m;
	rep (i, 0, n-1){
		cin>>l>>r;
		rep (j, l, r) f[j]=1;
	}
	// rep (i, 1, m) cout<<i<<" "<<f[i]<<endl;
	vector<int> v;
	int kiri, kanan;
	rep (i, 1, m){
		// if (f[i]==0){
		// 	kiri=i;
		// 	rep (j, i+1, m){
		// 		if (f[j]==0){
		// 			kanan=j;
		// 			f[j]=1;
		// 		}else{
		// 			break;
		// 		}
		// 	}
		// 	v.pb(make_pair(kiri, kanan));
		// }
		if (f[i]==0) v.pb(i);
	}
	if (v.size()==0){
		cout<<0<<endl;
		return 0;
	}
	cout<<v.size()<<endl;
	rep (i, 0, v.size()-1){
		if (i>0) cout<<" ";
		cout<<v[i];
	}
	cout<<endl;
	return 0;
}


#include<bits/stdc++.h>
#define FASTER ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(int i=a; i<=b; i++)
#define repp(i,a,b) for(int i=a; i>=b; i--)
#define nrep(i,a,b,c) for(int i=a; i<=b; i+=c)
#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define endl '\n'
#define Endl '\n'
#define ld long double

const double pi=acos(-1.0);
const char digit[]={'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};

using namespace std;
	int n, m;
	int l, r, f[101]={};
int main(){
	#ifndef ONLINE_JUDGE
	     freopen("input.txt", "r", stdin);
	     freopen("output.txt", "w", stdout);
	#endif
	cin>>n>>m;
	rep (i, 0, n-1){
		cin>>l>>r;
		rep (j, l, r) f[j]=1;
	}
	// rep (i, 1, m) cout<<i<<" "<<f[i]<<endl;
	vector<pii> v;
	int kiri, kanan;
	rep (i, 1, m){
		if (f[i]==0){
			kiri=i;
			rep (j, i+1, m){
				if (f[j]==0){
					kanan=j;
					f[j]=1;
				}else{
					break;
				}
			}
			v.pb(make_pair(kiri, kanan));
		}
	}
	if (v.size()==0){
		cout<<0<<endl;
		return 0;
	}
	cout<<v.size()<<endl;
	rep (i, 0, v.size()-1) cout<<v[i].ff<<" "<<v[i].ss<<endl;
	return 0;
}


#include<bits/stdc++.h>
#define FASTER ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(int i=a; i<=b; i++)
#define repp(i,a,b) for(int i=a; i>=b; i--)
#define nrep(i,a,b,c) for(int i=a; i<=b; i+=c)
#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define endl '\n'
#define Endl '\n'
#define ld long double

const double pi=acos(-1.0);
const char digit[]={'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};

using namespace std;
int main(){
	#ifndef ONLINE_JUDGE
	     freopen("input.txt", "r", stdin);
	     freopen("output.txt", "w", stdout);
	#endif

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
bool compare(pair<int,int> a, pair<int,int> b)
{
    return (a.first < b.first);
}
int main()
{
    int n,m,x,y;
    cin >> n >> m;
    vector<pair<int, int> >  vect;
    for(int i=0;i<n;i++)
    {cin >> x >> y;
    vect.push_back({x,y});}
    sort(vect.begin(),vect.end(),compare);
    x = 1;
    vector<int > result;
    for(int i=0;i<n;i++)
    {
       while(x < vect[i].first)
       {
           result.push_back(x);
           x++;
           if(x == m) break;
       }
       if(x == m)break;
       while(x >= vect[i].first and x <= vect[i].second)
       {x++;
       if(x == m) break;}
       if(x == m) break;
    }
    while(x <= m)
    {result.push_back(x);x++;}
    cout << result.size() <<endl;
    for(int i=0;i<result.size();i++)
    cout << result[i] <<" ";
}


#include<bits/stdc++.h>
using namespace std;
bool compare(pair<int,int> a, pair<int,int> b)
{
    return (a.first < b.first);
}
int main()
{
    int n,m,x,y;
    cin >> n >> m;
    vector<pair<int, int> >  vect;
    for(int i=0;i<n;i++)
    {cin >> x >> y;
    vect.push_back({x,y});}
    sort(vect.begin(),vect.end(),compare);
    x = 1;
    vector<int > result;
    for(int i=0;i<n;i++)
    {
       while(x < vect[i].first)
       {
           result.push_back(x);
           x++;
           if(x == m) break;
       }
       if(x == m)break;
       while(x >= vect[i].first and x <= vect[i].second)
       {x++;
       if(x == m) break;}
       if(x == m) break;
    }
    cout << result.size() <<endl;
    for(int i=0;i<result.size();i++)
    cout << result[i] <<" ";
}