import java.util.*;
import java.io.*;

public class solution
	{	public static int tonumb(String a)
			{
				return Integer.parseInt(a);
			}

		public static void toint(int arr[],String a)
			{
				String s[] = a.split(" ");

				int i;

				for(i=0;i<s.length;i++)
					{
						arr[i] = tonumb(s[i]);
					}
				return;
			}

		public static void print(int a)
			{
				System.out.println(a);
			}
		public static void print(String a)
			{
				System.out.println(a);
			}

		public static void main(String args[]) throws Exception
			{
				BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

				int temp[] = new int[3];

				toint(temp,br.readLine());

				int n = temp[0];
				int m = temp[1];

				int colors[] = new int[n+1];
				boolean assigned[]= new boolean[n+1];

				int i;

				int dance[][] = new int[n][3];

				for(i=0;i<m;i++)
				{
					toint(dance[i],br.readLine());
				}

				boolean valid = false;

				int j;

				for(i=1;i<=3;i++)
				{
					Arrays.fill(assigned,false);

					for(j=0;j<m;j++)
					{
						if(j==0)
						{
							colors[dance[j][0]] = i;
							assigned[dance[j][0]] = true;

							assignexc(0,dance,colors,j,assigned);
						}

						else
						{
							if(assigned[dance[j][0]])
								assignexc(0,dance,colors,j,assigned);

							else if(assigned[dance[j][1]])
								assignexc(1,dance,colors,j,assigned);

							else if(assigned[dance[j][2]])
								assignexc(2,dance,colors,j,assigned);
							else
								assignexc(-1,dance,colors,j,assigned);
						}
					}

					break;
				}

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

						System.out.print(colors[i]+" ");
					}

			}

		public static void assignexc(int n, int dance[][], int colors[], int j,boolean assigned[])
			{
				if(n==-1)
					{
						assigned[dance[j][0]] = true;
						assigned[dance[j][1]] = true;
						assigned[dance[j][2]] = true;

						colors[dance[j][0]] = 1;
						colors[dance[j][1]] = 2;
						colors[dance[j][2]] = 3;
					}

				else if(n==0)
					{
						int x = colors[dance[j][0]];

						assigned[dance[j][1]] = true;
						assigned[dance[j][2]] = true;

						if(x==1)
						{
						colors[dance[j][1]] = 2;
						colors[dance[j][2]] = 3;
						}
						else if(x==2)
						{
							colors[dance[j][1]] = 1;
							colors[dance[j][2]] = 3;

						}
						else
						{
							colors[dance[j][1]] = 1;
							colors[dance[j][2]] = 2;

						}
					}

				else if(n==1)
				{
					int x = colors[dance[j][1]];

						assigned[dance[j][0]] = true;
						assigned[dance[j][2]] = true;

						if(x==1)
						{
						colors[dance[j][0]] = 2;
						colors[dance[j][2]] = 3;
						}
						else if(x==2)
						{
							colors[dance[j][0]] = 1;
							colors[dance[j][2]] = 3;

						}
						else
						{
							colors[dance[j][0]] = 1;
							colors[dance[j][2]] = 2;

						}
				}

				else
				{
					int x = colors[dance[j][2]];

						assigned[dance[j][0]] = true;
						assigned[dance[j][1]] = true;

						if(x==1)
						{
						colors[dance[j][0]] = 2;
						colors[dance[j][1]] = 3;
						}
						else if(x==2)
						{
							colors[dance[j][0]] = 1;
							colors[dance[j][1]] = 3;

						}
						else
						{
							colors[dance[j][0]] = 1;
							colors[dance[j][1]] = 2;

						}
				}

			}

	}


import java.io.*;
import java.util.*;

public class B {

    public static void main(String[] args) throws IOException {
        B solver = new B();
        solver.solve();
    }

    private Set<Integer>[] g;
    private int[] colors;

    private void solve() throws IOException {
        FastScanner sc = new FastScanner(System.in);
//        sc = new FastScanner("7 3\n" +
//                "1 2 3\n" +
//                "4 5 6\n" +
//                "1 4 7\n");
//        sc = new FastScanner("7 3\n" +
//                "1 2 3\n" +
//                "1 4 5\n" +
//                "4 6 7\n");
//        sc = new FastScanner("5 2\n" +
//                "4 1 5\n" +
//                "3 1 2\n");

        int n = sc.nextInt();
        int m = sc.nextInt();

        g = new HashSet[n];
        for (int i = 0; i < n; i++) {
            g[i] = new HashSet<Integer>();
        }

        for (int i = 0; i < m; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            int c = sc.nextInt() - 1;

            g[a].add(b);
            g[a].add(c);
            g[b].add(a);
            g[b].add(c);
            g[c].add(a);
            g[c].add(b);
        }

        colors = new int[n];

        for (int i = 0; i < n; i++) {
            if (colors[i] == 0) {
                dfs(i);
            }
        }

        StringBuilder sb = new StringBuilder();
        for (int c : colors) {
            sb.append(c);
            sb.append(' ');
        }
        System.out.println(sb.toString());

    }

    private boolean dfs(int v) {
        if (colors[v] > 0) return true;
        int[] trycolors = {1, 2, 3};
        NEXT_COLOR:
        for (int c : trycolors) {
            for (int u : g[v]) {
                if (colors[u] == c) continue NEXT_COLOR;
            }
            colors[v] = c;
            boolean res = true;
            for (int u : g[v]) {
                res &= dfs(u);
                if (!res) break;
            }
            if (res) return true;
            colors[v] = 0;
        }
        return false;
    }

    public static class FastScanner {
        private BufferedReader br;
        private StringTokenizer st;

        public FastScanner(InputStream in) throws IOException {
            br = new BufferedReader(new InputStreamReader(in));
        }

        public FastScanner(File file) throws IOException {
            br = new BufferedReader(new FileReader(file));
        }

        public FastScanner(String s) {
            br = new BufferedReader(new StringReader(s));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                    return "";
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }
    }

}


import java.io.*;
import java.util.*;

public class B {

    public static void main(String[] args) throws IOException {
        B solver = new B();
        solver.solve();
    }

    private int[][] g;
    private int[] len;
    private int[] colors;

    private void solve() throws IOException {
        FastScanner sc = new FastScanner(System.in);
//        sc = new FastScanner("7 3\n" +
//                "1 2 3\n" +
//                "4 5 6\n" +
//                "1 4 7\n");
//        sc = new FastScanner("7 3\n" +
//                "1 2 3\n" +
//                "1 4 5\n" +
//                "4 6 7\n");
//        sc = new FastScanner("5 2\n" +
//                "4 1 5\n" +
//                "3 1 2\n");

        int n = sc.nextInt();
        int m = sc.nextInt();

        g = new int[n][4];
        len = new int[n];

        for (int i = 0; i < m; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            int c = sc.nextInt() - 1;

            g[a][len[a]++] = b;
            g[a][len[a]++] = c;
            g[b][len[b]++] = a;
            g[b][len[b]++] = c;
            g[c][len[c]++] = a;
            g[c][len[c]++] = b;
        }

        colors = new int[n];

        dfs(0);

        StringBuilder sb = new StringBuilder();
        for (int c : colors) {
            sb.append(c);
            sb.append(' ');
        }
        System.out.println(sb.toString());

    }

    private boolean dfs(int v) {
        if (colors[v] > 0) return true;
        int[] trycolors = {1,2,3};
        NEXT_COLOR:
        for (int c : trycolors) {
            for (int i = 0; i < len[v]; i++) {
                int u = g[v][i];
                if (colors[u] == c) continue NEXT_COLOR;
            }
            colors[v] = c;
            boolean res = true;
            for (int i = 0; i < len[v]; i++) {
                int u = g[v][i];
                res &= dfs(u);
                if (!res) break;
            }
            if (res) return true;
            colors[v] = 0;
        }
        return false;
    }

    public static class FastScanner {
        private BufferedReader br;
        private StringTokenizer st;

        public FastScanner(InputStream in) throws IOException {
            br = new BufferedReader(new InputStreamReader(in));
        }

        public FastScanner(File file) throws IOException {
            br = new BufferedReader(new FileReader(file));
        }

        public FastScanner(String s) {
            br = new BufferedReader(new StringReader(s));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                    return "";
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }
    }

}


import java.io.*;
import java.util.*;

public class B {

    public static void main(String[] args) throws IOException {
        B solver = new B();
        solver.solve();
    }

    private int[][] g;
    private int[] len;
    private int[] colors;

    private void solve() throws IOException {
        FastScanner sc = new FastScanner(System.in);
//        sc = new FastScanner("7 3\n" +
//                "1 2 3\n" +
//                "4 5 6\n" +
//                "1 4 7\n");
//        sc = new FastScanner("7 3\n" +
//                "1 2 3\n" +
//                "1 4 5\n" +
//                "4 6 7\n");
//        sc = new FastScanner("5 2\n" +
//                "4 1 5\n" +
//                "3 1 2\n");

        int n = sc.nextInt();
        int m = sc.nextInt();

        g = new int[n][4];
        len = new int[n];

        for (int i = 0; i < m; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            int c = sc.nextInt() - 1;

            g[a][len[a]++] = b;
            g[a][len[a]++] = c;
            g[b][len[b]++] = a;
            g[b][len[b]++] = c;
            g[c][len[c]++] = a;
            g[c][len[c]++] = b;
        }

        colors = new int[n];

        for (int i = 0; i < n; i++) {
            if (colors[i] == 0) {
                dfs(i);
            }
        }

        StringBuilder sb = new StringBuilder();
        for (int c : colors) {
            sb.append(c);
            sb.append(' ');
        }
        System.out.println(sb.toString());

    }

    private boolean dfs(int v) {
        if (colors[v] > 0) return true;
        int[] trycolors = {1,2,3};
        NEXT_COLOR:
        for (int c : trycolors) {
            for (int i = 0; i < len[v]; i++) {
                int u = g[v][i];
                if (colors[u] == c) continue NEXT_COLOR;
            }
            colors[v] = c;
            boolean res = true;
            for (int i = 0; i < len[v]; i++) {
                int u = g[v][i];
                res &= dfs(u);
                if (!res) break;
            }
            if (res) return true;
            colors[v] = 0;
        }
        return false;
    }

    public static class FastScanner {
        private BufferedReader br;
        private StringTokenizer st;

        public FastScanner(InputStream in) throws IOException {
            br = new BufferedReader(new InputStreamReader(in));
        }

        public FastScanner(File file) throws IOException {
            br = new BufferedReader(new FileReader(file));
        }

        public FastScanner(String s) {
            br = new BufferedReader(new StringReader(s));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                    return "";
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }
    }

}


import java.io.*;
import java.util.*;

public class B {

    public static void main(String[] args) throws IOException {
        B solver = new B();
        solver.solve();
    }

    private int[][] g;
    private int[] len;
    private int[] colors;

    private void solve() throws IOException {
        FastScanner sc = new FastScanner(System.in);
//        sc = new FastScanner("7 3\n" +
//                "1 2 3\n" +
//                "4 5 6\n" +
//                "1 4 7\n");
//        sc = new FastScanner("7 3\n" +
//                "1 2 3\n" +
//                "1 4 5\n" +
//                "4 6 7\n");
//        sc = new FastScanner("5 2\n" +
//                "4 1 5\n" +
//                "3 1 2\n");

        int n = sc.nextInt();
        int m = sc.nextInt();

        g = new int[n][10];
        len = new int[n];

        for (int i = 0; i < m; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            int c = sc.nextInt() - 1;

            g[a][len[a]++] = b;
            g[a][len[a]++] = c;
            g[b][len[b]++] = a;
            g[b][len[b]++] = c;
            g[c][len[c]++] = a;
            g[c][len[c]++] = b;
        }

        colors = new int[n];

        for (int i = 0; i < n; i++) {
            if (colors[i] == 0) {
                dfs(i);
            }
        }

        StringBuilder sb = new StringBuilder();
        for (int c : colors) {
            sb.append(c);
            sb.append(' ');
        }
        System.out.println(sb.toString());

    }

    private boolean dfs(int v) {
        if (colors[v] > 0) return true;
        int[] trycolors = {1,2,3};
        NEXT_COLOR:
        for (int c : trycolors) {
            for (int i = 0; i < len[v]; i++) {
                int u = g[v][i];
                if (colors[u] == c) continue NEXT_COLOR;
            }
            colors[v] = c;
            boolean res = true;
            for (int i = 0; i < len[v]; i++) {
                int u = g[v][i];
                res &= dfs(u);
                if (!res) break;
            }
            if (res) return true;
            colors[v] = 0;
        }
        return false;
    }

    public static class FastScanner {
        private BufferedReader br;
        private StringTokenizer st;

        public FastScanner(InputStream in) throws IOException {
            br = new BufferedReader(new InputStreamReader(in));
        }

        public FastScanner(File file) throws IOException {
            br = new BufferedReader(new FileReader(file));
        }

        public FastScanner(String s) {
            br = new BufferedReader(new StringReader(s));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                    return "";
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }
    }

}


import java.util.*;

public class FlagDay357B
{
    public static void main(String[] args)
    {
        // Set up scanner
        Scanner sc = new Scanner(System.in);
        // System.out.println("Enter n");
        int n = sc.nextInt();
        // System.out.println("Enter m");
        int m = sc.nextInt();

        ArrayList<Integer> one23 = new ArrayList<Integer>();
        one23.add(1);
        one23.add(2);
        one23.add(3);

        int[] dancercolor = new int[n+1];
        for (int i=0; i<m; i++)
        {
            // System.out.println("Input first dancer");
            int one = sc.nextInt();
            // System.out.println("Input second dancer");
            int two = sc.nextInt();
            // System.out.println("Input third dancer");
            int three = sc.nextInt();
            int onecolor = dancercolor[one];
            int twocolor = dancercolor[two];
            int threecolor = dancercolor[three];
            if (onecolor != 0)   // Dancer one has already danced
            {
                one23.remove(new Integer(onecolor));
                dancercolor[two] = one23.get(0);
                dancercolor[three] = one23.get(1);
                one23.add(onecolor);
            }
            else if (twocolor != 0)
            {
                one23.remove(new Integer(twocolor));
                dancercolor[two] = one23.get(0);
                dancercolor[three] = one23.get(1);
                one23.add(twocolor);
            }
            else if (threecolor != 0)
            {
                one23.remove(new Integer(threecolor));
                dancercolor[two] = one23.get(0);
                dancercolor[three] = one23.get(1);
                one23.add(threecolor);
            }
            else    // All three are new--assign at random
            {
                dancercolor[one] = one23.get(0);
                dancercolor[two] = one23.get(1);
                dancercolor[three] = one23.get(2);
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i=1; i<=n; i++)
        {
            sb.append(dancercolor[i] + " ");
        }
        System.out.println(sb);
    }
}


import java.util.*;

public class FlagDay357B
{
    public static void main(String[] args)
    {
        // Set up scanner
        Scanner sc = new Scanner(System.in);
        // System.out.println("Enter n");
        int n = sc.nextInt();
        // System.out.println("Enter m");
        int m = sc.nextInt();

        ArrayList<Integer> one23 = new ArrayList<Integer>();
        one23.add(1);
        one23.add(2);
        one23.add(3);

        int[] dancercolor = new int[n+1];
        for (int i=0; i<m; i++)
        {
            // System.out.println("Input first dancer");
            int one = sc.nextInt();
            // System.out.println("Input second dancer");
            int two = sc.nextInt();
            // System.out.println("Input third dancer");
            int three = sc.nextInt();
            int onecolor = dancercolor[one];
            int twocolor = dancercolor[two];
            int threecolor = dancercolor[three];
            if (onecolor != 0)   // Dancer one has already danced
            {
                one23.remove(new Integer(onecolor));
                dancercolor[two] = one23.get(0);
                dancercolor[three] = one23.get(1);
                one23.add(onecolor);
            }
            else if (twocolor != 0)
            {
                one23.remove(new Integer(twocolor));
                dancercolor[one] = one23.get(0);
                dancercolor[three] = one23.get(1);
                one23.add(twocolor);
            }
            else if (threecolor != 0)
            {
                one23.remove(new Integer(threecolor));
                dancercolor[one] = one23.get(0);
                dancercolor[two] = one23.get(1);
                one23.add(threecolor);
            }
            else    // All three are new--assign at random
            {
                dancercolor[one] = one23.get(0);
                dancercolor[two] = one23.get(1);
                dancercolor[three] = one23.get(2);
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i=1; i<=n; i++)
        {
            sb.append(dancercolor[i] + " ");
        }
        System.out.println(sb);
    }
}


import java.util.*;

public class FlagDay357B
{
    public static void main(String[] args)
    {
        // Set up scanner
        Scanner sc = new Scanner(System.in);
        // System.out.println("Enter n");
        int n = sc.nextInt();
        // System.out.println("Enter m");
        int m = sc.nextInt();

        ArrayList<Integer> one23 = new ArrayList<Integer>();
        one23.add(1);
        one23.add(2);
        one23.add(3);

        int[] dancercolor = new int[n+1];
        for (int i=0; i<m; i++)
        {
            System.out.println("Input first dancer");
            int one = sc.nextInt();
            System.out.println("Input second dancer");
            int two = sc.nextInt();
            System.out.println("Input third dancer");
            int three = sc.nextInt();
            int onecolor = dancercolor[one];
            int twocolor = dancercolor[two];
            int threecolor = dancercolor[three];
            if (onecolor != 0)   // Dancer one has already danced
            {
                one23.remove(new Integer(onecolor));
                dancercolor[two] = one23.get(0);
                dancercolor[three] = one23.get(1);
                one23.add(onecolor);
            }
            else if (twocolor != 0)
            {
                one23.remove(new Integer(twocolor));
                dancercolor[two] = one23.get(0);
                dancercolor[three] = one23.get(1);
                one23.add(twocolor);
            }
            else if (threecolor != 0)
            {
                one23.remove(new Integer(threecolor));
                dancercolor[two] = one23.get(0);
                dancercolor[three] = one23.get(1);
                one23.add(threecolor);
            }
            else    // All three are new--assign at random
            {
                dancercolor[one] = one23.get(0);
                dancercolor[two] = one23.get(1);
                dancercolor[three] = one23.get(2);
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i=1; i<=n; i++)
        {
            sb.append(dancercolor[i] + " ");
        }
        System.out.println(sb);
    }
}


function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i]);
	};
	return tokens;
}

function main() {
	var data = tokenizeIntegers(readline());
	var dancerNum = data[0], partyNum = data[1];

	var colors = new Array(dancerNum);
	var colorVariety = 3;
	var initialAssignment = [];
	for (var color = 0; color < colorVariety; ++color) {
		initialAssignment.push(color);
	}

	for (var partyIx = 0; partyIx < partyNum; ++partyIx) {
		var party = tokenizeIntegers(readline());
		var assignment = initialAssignment.slice(0);
		for (var dancerIx = 0; dancerIx < colorVariety; ++dancerIx) {
			var dancer = party[dancerIx]-1;
			if (colors[dancer] != undefined) {
				assignment[dancerIx] = colors[dancer];
				assignment[colors[dancer]] = dancerIx;
				break;
			}
		}
		for (dancerIx = 0; dancerIx < colorVariety; ++dancerIx) {
			colors[party[dancerIx]-1] = assignment[dancerIx];
		}
	}

	for (var colorIx = 0; colorIx < dancerNum; ++colorIx) {
		colors[colorIx] += 1;
	}
	print(colors.join(" "));
}

main();


#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <string>
#include <set>
#include <list>
#include <map>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef map<int,int>mii;
typedef map<string,int> msi;

#define popcount(a) __builtin_popcount(a)
#define pi acos(-1.0)
#define INF 2147483647
#define sqr(x) ((x)*(x))
#define all(x) x.begin(),x.end()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) ((a)*((b)/gcd(a,b)))
#define rep(i,n) for(int i=0;i<n;i++)
#define repi(i,m,n) for(int i=m;i<=n;i++)
#define repr(i,m,n) for(int i=m;i>=n;i--)
#define MEM(a,b) memset(a,b,sizeof(a))
#define pb push_back

int dx[]={-1,0,1,0,-1,1,1,-1},dy[]={0,-1,0,1,-1,-1,1,1};
int kx[]={2,1,-1,-2,-2,-1,1,2},ky[]={1,2,2,1,-1,-2,-2,-1};

bool isVowel(char ch){ch=tolower(ch);return ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u';}
ll bigmod(ll B,ll P,ll M){ll R=1;while(P>0){if(P%2){R=(R*B)%M;}P/=2;B=(B*B)%M;}return (int)R;}
ll nCr(double n,double r){double ans=1;if(r>n-r)r=n-r;repi(i,1,r){ans*=(n-i+1);ans/=i;}return (ll)ans;}
string toString(int n){stringstream ss;ss<<n;return ss.str();}
int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;}
int POW(int b,int p){int r=1;repi(i,1,p)r*=b;return r;}
//void sieve(int n){MEM(prime,1);for(int i=2;i*i<=n;i++)for(int j=i*i;j<=n;j+=i)prime[j]=0;}
int col[100007];
int a[3];
int main()
{
    //freopen("i.txt","r",stdin);
    //freopen("o.txt","w",stdout);

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

    MEM(col, -1);

    rep(i, m) {
        int k = 1;
        rep(j, 3) {
            cin >> a[j];
            if(col[a[j]] == -1) col[a[j]] = k++;
            else if(col[a[j]] == k) k++;
        }
    }
    repi(i,1,n) cout<<col[i] <<' ';

/*
    int a, b, c, pa, pb, pc;
    cin >> a >> b >> c;
    col[a] = 1, col[b] = 2, col[c] = 3;
    pa = a, pb = b, pc = c;

    rep(i, m - 1) {
        cin >> a >> b >> c;
        if(a == pa || a == pb || a == pc) {
            if(col[a]==1) col[b] = 2, col[c] = 3;
            if(col[a]==2) col[b] = 1, col[c] = 3;
            if(col[a]==3) col[b] = 1, col[c] = 2;
        } else if(b == pa || b == pb ||b == pc) {
            if(col[b]==1) col[c] = 2, col[a] = 3;
            if(col[b]==2) col[c] = 1, col[a] = 3;
            if(col[b]==3) col[c] = 1, col[a] = 2;
        } else if(c == pa || c == pb ||c == pc) {
            if(col[c]==1) col[a] = 2, col[b] = 3;
            if(col[c]==2) col[a] = 1, col[b] = 3;
            if(col[c]==3) col[a] = 1, col[b] = 2;
        }
          else col[a] = 1, col[b] = 2, col[c] = 3;

        pa = a, pb = b, pc = c;
    }

    repi(i,1,n) cout<<col[i] <<' ';
    */

    return 0;
}


#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <string>
#include <set>
#include <list>
#include <map>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef map<int,int>mii;
typedef map<string,int> msi;

#define popcount(a) __builtin_popcount(a)
#define pi acos(-1.0)
#define INF 2147483647
#define sqr(x) ((x)*(x))
#define all(x) x.begin(),x.end()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) ((a)*((b)/gcd(a,b)))
#define rep(i,n) for(int i=0;i<n;i++)
#define repi(i,m,n) for(int i=m;i<=n;i++)
#define repr(i,m,n) for(int i=m;i>=n;i--)
#define MEM(a,b) memset(a,b,sizeof(a))
#define pb push_back

int dx[]={-1,0,1,0,-1,1,1,-1},dy[]={0,-1,0,1,-1,-1,1,1};
int kx[]={2,1,-1,-2,-2,-1,1,2},ky[]={1,2,2,1,-1,-2,-2,-1};

bool isVowel(char ch){ch=tolower(ch);return ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u';}
ll bigmod(ll B,ll P,ll M){ll R=1;while(P>0){if(P%2){R=(R*B)%M;}P/=2;B=(B*B)%M;}return (int)R;}
ll nCr(double n,double r){double ans=1;if(r>n-r)r=n-r;repi(i,1,r){ans*=(n-i+1);ans/=i;}return (ll)ans;}
string toString(int n){stringstream ss;ss<<n;return ss.str();}
int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;}
int POW(int b,int p){int r=1;repi(i,1,p)r*=b;return r;}
//void sieve(int n){MEM(prime,1);for(int i=2;i*i<=n;i++)for(int j=i*i;j<=n;j+=i)prime[j]=0;}
int col[100007];
int main()
{
    //freopen("i.txt","r",stdin);
    //freopen("o.txt","w",stdout);

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

    int a, b, c, pa, pb, pc;
    cin >> a >> b >> c;
    col[a] = 1, col[b] = 2, col[c] = 3;
    pa = a, pb = b, pc = c;

    rep(i,m-1) {
        cin >> a >> b >> c;
        if(a == pa || a == pb || a == pc) {
            if     (a == pa) col[a] = col[pa];
            else if(a == pb) col[a] = col[pb];
            else if(a == pc) col[a] = col[pc];

            if(col[a]==1) col[b] = 2, col[c] = 3;
            if(col[a]==2) col[b] = 1, col[c] = 3;
            if(col[a]==3) col[b] = 1, col[c] = 2;
        } else if(b == pa || b == pb ||b == pc) {
            if     (b == pa) col[b] = col[pa];
            else if(b == pb) col[b] = col[pb];
            else if(b == pc) col[b] = col[pc];

            if(col[b]==1) col[c] = 2, col[a] = 3;
            if(col[b]==2) col[c] = 1, col[a] = 3;
            if(col[b]==3) col[c] = 1, col[a] = 2;
        } else if(c == pa || c == pb ||c == pc) {
            if     (c == pa) col[c] = col[pa];
            else if(c == pb) col[c] = col[pb];
            else if(c == pc) col[c] = col[pc];

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

        pa = a, pb = b, pc = c;
    }

    repi(i,1,n) cout<<col[i] <<' ';
    return 0;
}


#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <string>
#include <set>
#include <list>
#include <map>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef map<int,int>mii;
typedef map<string,int> msi;

#define popcount(a) __builtin_popcount(a)
#define pi acos(-1.0)
#define INF 2147483647
#define sqr(x) ((x)*(x))
#define all(x) x.begin(),x.end()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) ((a)*((b)/gcd(a,b)))
#define rep(i,n) for(int i=0;i<n;i++)
#define repi(i,m,n) for(int i=m;i<=n;i++)
#define repr(i,m,n) for(int i=m;i>=n;i--)
#define MEM(a,b) memset(a,b,sizeof(a))
#define pb push_back

int dx[]={-1,0,1,0,-1,1,1,-1},dy[]={0,-1,0,1,-1,-1,1,1};
int kx[]={2,1,-1,-2,-2,-1,1,2},ky[]={1,2,2,1,-1,-2,-2,-1};

bool isVowel(char ch){ch=tolower(ch);return ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u';}
ll bigmod(ll B,ll P,ll M){ll R=1;while(P>0){if(P%2){R=(R*B)%M;}P/=2;B=(B*B)%M;}return (int)R;}
ll nCr(double n,double r){double ans=1;if(r>n-r)r=n-r;repi(i,1,r){ans*=(n-i+1);ans/=i;}return (ll)ans;}
string toString(int n){stringstream ss;ss<<n;return ss.str();}
int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;}
int POW(int b,int p){int r=1;repi(i,1,p)r*=b;return r;}
//void sieve(int n){MEM(prime,1);for(int i=2;i*i<=n;i++)for(int j=i*i;j<=n;j+=i)prime[j]=0;}
int col[100007];
int a[3];
int main()
{
    //freopen("i.txt","r",stdin);
    //freopen("o.txt","w",stdout);

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

    MEM(col, -1);

    rep(i, m) {
        int k = 1;
        rep(j, 3) {
            cin >> a[j];
            if(col[a[j]] == -1) {
                if(col[a[0]]==k||col[a[1]]==k||col[a[2]]==k) k++;
                col[a[j]] = k++;
            }
        }
    }
    repi(i,1,n) cout<<col[i] <<' ';

/*
    int a, b, c, pa, pb, pc;
    cin >> a >> b >> c;
    col[a] = 1, col[b] = 2, col[c] = 3;
    pa = a, pb = b, pc = c;

    rep(i, m - 1) {
        cin >> a >> b >> c;
        if(a == pa || a == pb || a == pc) {
            if(col[a]==1) col[b] = 2, col[c] = 3;
            if(col[a]==2) col[b] = 1, col[c] = 3;
            if(col[a]==3) col[b] = 1, col[c] = 2;
        } else if(b == pa || b == pb ||b == pc) {
            if(col[b]==1) col[c] = 2, col[a] = 3;
            if(col[b]==2) col[c] = 1, col[a] = 3;
            if(col[b]==3) col[c] = 1, col[a] = 2;
        } else if(c == pa || c == pb ||c == pc) {
            if(col[c]==1) col[a] = 2, col[b] = 3;
            if(col[c]==2) col[a] = 1, col[b] = 3;
            if(col[c]==3) col[a] = 1, col[b] = 2;
        }
          else col[a] = 1, col[b] = 2, col[c] = 3;

        pa = a, pb = b, pc = c;
    }

    repi(i,1,n) cout<<col[i] <<' ';
    */

    return 0;
}


#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <string>
#include <set>
#include <list>
#include <map>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef map<int,int>mii;
typedef map<string,int> msi;

#define popcount(a) __builtin_popcount(a)
#define pi acos(-1.0)
#define INF 2147483647
#define sqr(x) ((x)*(x))
#define all(x) x.begin(),x.end()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) ((a)*((b)/gcd(a,b)))
#define rep(i,n) for(int i=0;i<n;i++)
#define repi(i,m,n) for(int i=m;i<=n;i++)
#define repr(i,m,n) for(int i=m;i>=n;i--)
#define MEM(a,b) memset(a,b,sizeof(a))
#define pb push_back

int dx[]={-1,0,1,0,-1,1,1,-1},dy[]={0,-1,0,1,-1,-1,1,1};
int kx[]={2,1,-1,-2,-2,-1,1,2},ky[]={1,2,2,1,-1,-2,-2,-1};

bool isVowel(char ch){ch=tolower(ch);return ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u';}
ll bigmod(ll B,ll P,ll M){ll R=1;while(P>0){if(P%2){R=(R*B)%M;}P/=2;B=(B*B)%M;}return (int)R;}
ll nCr(double n,double r){double ans=1;if(r>n-r)r=n-r;repi(i,1,r){ans*=(n-i+1);ans/=i;}return (ll)ans;}
string toString(int n){stringstream ss;ss<<n;return ss.str();}
int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;}
int POW(int b,int p){int r=1;repi(i,1,p)r*=b;return r;}
//void sieve(int n){MEM(prime,1);for(int i=2;i*i<=n;i++)for(int j=i*i;j<=n;j+=i)prime[j]=0;}
int col[100007];
int a[3];
int main()
{
    //freopen("i.txt","r",stdin);
    //freopen("o.txt","w",stdout);

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

    MEM(col, -1);

    rep(i, m) {
        int k = 1;
        rep(j, 3) {
            cin >> a[j];
            if(col[a[j]] == -1) {
                if(col[a[0]]==k||col[a[1]]==k||col[a[2]]==k) k++;
                col[a[j]] = k++;
            }
            else if(col[a[j]] == k) k++;
        }
    }
    repi(i,1,n) cout<<col[i] <<' ';

/*
    int a, b, c, pa, pb, pc;
    cin >> a >> b >> c;
    col[a] = 1, col[b] = 2, col[c] = 3;
    pa = a, pb = b, pc = c;

    rep(i, m - 1) {
        cin >> a >> b >> c;
        if(a == pa || a == pb || a == pc) {
            if(col[a]==1) col[b] = 2, col[c] = 3;
            if(col[a]==2) col[b] = 1, col[c] = 3;
            if(col[a]==3) col[b] = 1, col[c] = 2;
        } else if(b == pa || b == pb ||b == pc) {
            if(col[b]==1) col[c] = 2, col[a] = 3;
            if(col[b]==2) col[c] = 1, col[a] = 3;
            if(col[b]==3) col[c] = 1, col[a] = 2;
        } else if(c == pa || c == pb ||c == pc) {
            if(col[c]==1) col[a] = 2, col[b] = 3;
            if(col[c]==2) col[a] = 1, col[b] = 3;
            if(col[c]==3) col[a] = 1, col[b] = 2;
        }
          else col[a] = 1, col[b] = 2, col[c] = 3;

        pa = a, pb = b, pc = c;
    }

    repi(i,1,n) cout<<col[i] <<' ';
    */

    return 0;
}


#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <string>
#include <set>
#include <list>
#include <map>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef map<int,int>mii;
typedef map<string,int> msi;

#define popcount(a) __builtin_popcount(a)
#define pi acos(-1.0)
#define INF 2147483647
#define sqr(x) ((x)*(x))
#define all(x) x.begin(),x.end()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) ((a)*((b)/gcd(a,b)))
#define rep(i,n) for(int i=0;i<n;i++)
#define repi(i,m,n) for(int i=m;i<=n;i++)
#define repr(i,m,n) for(int i=m;i>=n;i--)
#define MEM(a,b) memset(a,b,sizeof(a))
#define pb push_back

int dx[]={-1,0,1,0,-1,1,1,-1},dy[]={0,-1,0,1,-1,-1,1,1};
int kx[]={2,1,-1,-2,-2,-1,1,2},ky[]={1,2,2,1,-1,-2,-2,-1};

bool isVowel(char ch){ch=tolower(ch);return ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u';}
ll bigmod(ll B,ll P,ll M){ll R=1;while(P>0){if(P%2){R=(R*B)%M;}P/=2;B=(B*B)%M;}return (int)R;}
ll nCr(double n,double r){double ans=1;if(r>n-r)r=n-r;repi(i,1,r){ans*=(n-i+1);ans/=i;}return (ll)ans;}
string toString(int n){stringstream ss;ss<<n;return ss.str();}
int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;}
int POW(int b,int p){int r=1;repi(i,1,p)r*=b;return r;}
//void sieve(int n){MEM(prime,1);for(int i=2;i*i<=n;i++)for(int j=i*i;j<=n;j+=i)prime[j]=0;}
int col[100007];
int a[3];
int main()
{
    //freopen("i.txt","r",stdin);
    //freopen("o.txt","w",stdout);

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

    MEM(col, -1);

    rep(i, m) {
        int k = 1;
        rep(j, 3) cin >> a[j];
        rep(j, 3) {
            if(col[a[j]] == -1) {
                if(col[a[0]]==k||col[a[1]]==k||col[a[2]]==k) k++;
                col[a[j]] = k++;
            }
        }
    }
    repi(i,1,n) cout<<col[i] <<' ';

/*
    int a, b, c, pa, pb, pc;
    cin >> a >> b >> c;
    col[a] = 1, col[b] = 2, col[c] = 3;
    pa = a, pb = b, pc = c;

    rep(i, m - 1) {
        cin >> a >> b >> c;
        if(a == pa || a == pb || a == pc) {
            if(col[a]==1) col[b] = 2, col[c] = 3;
            if(col[a]==2) col[b] = 1, col[c] = 3;
            if(col[a]==3) col[b] = 1, col[c] = 2;
        } else if(b == pa || b == pb ||b == pc) {
            if(col[b]==1) col[c] = 2, col[a] = 3;
            if(col[b]==2) col[c] = 1, col[a] = 3;
            if(col[b]==3) col[c] = 1, col[a] = 2;
        } else if(c == pa || c == pb ||c == pc) {
            if(col[c]==1) col[a] = 2, col[b] = 3;
            if(col[c]==2) col[a] = 1, col[b] = 3;
            if(col[c]==3) col[a] = 1, col[b] = 2;
        }
          else col[a] = 1, col[b] = 2, col[c] = 3;

        pa = a, pb = b, pc = c;
    }

    repi(i,1,n) cout<<col[i] <<' ';
    */

    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int main()
{
    vector<int> base,tmp;
    vector<int>::iterator iter;
    int dancers,dance,i,j,s;
    int color[100000]={0};
    long long int order[100000][3];

    cin>>dancers>>dance;

    for(i = 0; i < dance; i++)
    {
        for(j = 0; j < 3; j++)
        {
            cin>>order[i][j];
        }
        if(i == 0)
        {
            for(int k = 0; k < 3; k++)
            {
                base.push_back(k + 1);
                color[order[0][k]] = base[k];
            }
        }
        else
        {
            tmp = base;
            iter = tmp.begin();
            for(j = 0; j < 3; j++)
            {
                if(color[order[i][j]]!=0)
                {
                    iter += color[order[i][j]] - 1;
                    tmp.erase(iter);
                }

            }
            for(j = 0,s = 0; j < 3; j++)
            {
                if(color[order[i][j]] == 0)
                    color[order[i][j]] = tmp[s++];
            }

        }

    }
    for(i = 1; i <= dancers; i++)
        cout<<color[i]<<" ";
    return 0;

}


#include<iostream>
#include<vector>

using namespace std;
const int group = 3;

int main()
{
    vector<int> base;
    vector<int>::iterator iter;
    int dancers;
    int dance;
    int color[100] = {0};
    int order[100];
    int i,num,j;

    cin>>dancers>>dance;
    num = 3 * dance - 1;

    for(i = 0; i < num; i++)
    {
        cin>>order[i];
    }
    for(i = 0; i < dance; i++)
    {
        if(i == 0)
            for(j = 0;j < group; j++)
            {
                base.push_back(j + 1);
                color[order[j]] = base[j];
            }
        else
        {
            vector<int> tmp(base);
            for(j = i * group; j < (i + 1) * group; j++)
            {
                if(color[order[j]] != 0)
                {
                    iter = find(tmp.begin(),tmp.end(),color[order[j]]);
                    tmp.erase(iter);
                }
            }
            for(j = i * dance; j < (group + i * dance); j++)
            {
                int s = 0;
                if(color[order[j]] == 0)
                {
                    color[order[j]] = tmp[s];
                }
            }
        }
    }
    for(i = 0; i < num; i++)
    {
        cout<<color[i]<<" ";
    }
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int main()
{
    vector<int> base,tmp;
    vector<int>::iterator iter;
    int dancers,dance,i,j,s;
    int color[10000]={0};
    int order[10000][3];

    cin>>dancers>>dance;

    for(i = 0; i < dance; i++)
    {
        for(j = 0; j < 3; j++)
        {
            cin>>order[i][j];
        }
        if(i == 0)
        {
            for(int k = 0; k < 3; k++)
            {
                base.push_back(k + 1);
                color[order[0][k]] = base[k];
            }
        }
        else
        {
            tmp = base;
            iter = tmp.begin();
            for(j = 0; j < 3; j++)
            {
                if(color[order[i][j]]!=0)
                {
                    iter += color[order[i][j]] - 1;
                    tmp.erase(iter);
                }

            }
            for(j = 0,s = 0; j < 3; j++)
            {
                if(color[order[i][j]] == 0)
                    color[order[i][j]] = tmp[s++];
            }

        }

    }
    for(i = i; i < dancers; i++)
        cout<<color[i]<<" ";
    return 0;

}


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
const int group = 3;

int main()
{
    vector<int> base,tmp;
    vector<int>::iterator iter;
    int dancers;
    int dance;
    int color[100] = {0};
    int order[100];
    int i,num,j,s;

    cin>>dancers>>dance;

    num = 3 * dance;

    for(i = 0; i < num; i++)
    {
        cin>>order[i];
    }
    for(i = 0; i < dance; i++)
    {
        if(i == 0)
            for(j = 0;j < group; j++)
            {
                base.push_back(j + 1);
                color[order[j]] = base[j];
            }
        else
        {
            tmp = base;
            for(j = i * group; j < (i + 1) * group; j++)
            {
                if(color[order[j]] != 0)
                {
                    iter = find(tmp.begin(),tmp.end(),color[order[j]]);
                    tmp.erase(iter);
                }
            }
            for(j = i * group,s = 0; j < (1 + i) * group; j++)
            {
                if(color[order[j]] == 0)
                {
                    color[order[j]] = tmp[s++];
                }
            }
        }
    }
    for(i = 1; i <= dancers; i++)
    {
        cout<<color[i]<<" ";
    }
    return 0;
    //system("pause");
}


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
const int group = 3;

int main()
{
    vector<int> base;
    vector<int>::iterator iter;
    int dancers;
    int dance;
    int color[100] = {0};
    int order[100];
    int i,num,j;

    cin>>dancers>>dance;

    num = 3 * dance;

    for(i = 0; i < num; i++)
    {
        cin>>order[i];
    }
    for(i = 0; i < dance; i++)
    {
        if(i == 0)
            for(j = 0;j < group; j++)
            {
                base.push_back(j + 1);
                color[order[j]] = base[j];
            }
        else
        {
            vector<int> tmp(base);
            for(j = i * group; j < (i + 1) * group; j++)
            {
                if(color[order[j]] != 0)
                {
                    iter = find(tmp.begin(),tmp.end(),color[order[j]]);
                    tmp.erase(iter);
                }
            }
            for(j = i * group; j < (1 + i) * group; j++)
            {
                int s = 0;
                if(color[order[j]] == 0)
                {
                    color[order[j]] = tmp[s++];
                }
            }
        }
    }
    for(i = 0; i < dancers; i++)
    {
        cout<<color[i]<<" ";
    }
    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
const int group = 3;

int main()
{
    vector<int> base;
    vector<int>::iterator iter;
    int dancers;
    int dance;
    int color[100] = {0};
    int order[100];
    int i,num,j;

    cin>>dancers>>dance;

    num = 3 * dance - 1;

    for(i = 0; i < num; i++)
    {
        cin>>order[i];
    }
    for(i = 0; i < dance; i++)
    {
        if(i == 0)
            for(j = 0;j < group; j++)
            {
                base.push_back(j + 1);
                color[order[j]] = base[j];
            }
        else
        {
            vector<int> tmp(base);
            for(j = i * group; j < (i + 1) * group; j++)
            {
                if(color[order[j]] != 0)
                {
                    iter = find(tmp.begin(),tmp.end(),color[order[j]]);
                    tmp.erase(iter);
                }
            }
            for(j = i * group; j < (1 + i) * group; j++)
            {
                int s = 0;
                if(color[order[j]] == 0)
                {
                    color[order[j]] = tmp[s++];
                }
            }
        }
    }
    for(i = 0; i < dancers; i++)
    {
        cout<<color[i]<<" ";
    }
    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
const int group = 3;

int main()
{
    vector<int> base,tmp;
    vector<int>::iterator iter;
    int dancers;
    int dance;
    int color[10000] = {0};
    int order[10000];
    int i,num,j,s;

    cin>>dancers>>dance;

    num = 3 * dance;

    for(i = 0; i < num; i++)
    {
        cin>>order[i];
    }
    for(i = 0; i < dance; i++)
    {
        if(i == 0)
            for(j = 0;j < group; j++)
            {
                base.push_back(j + 1);
                color[order[j]] = base[j];
            }
        else
        {
            tmp = base;
            for(j = i * group; j < (i + 1) * group; j++)
            {
                if(color[order[j]] != 0)
                {
                    iter = find(tmp.begin(),tmp.end(),color[order[j]]);
                    tmp.erase(iter);
                }
            }
            for(j = i * group,s = 0; j < (1 + i) * group; j++)
            {
                if(color[order[j]] == 0)
                {
                    color[order[j]] = tmp[s++];
                }
            }
        }
    }
    for(i = 1; i <= dancers; i++)
    {
        cout<<color[i]<<" ";
    }
    return 0;
    //system("pause");
}


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
const int group = 3;

int main()
{
    vector<int> base,tmp;
    vector<int>::iterator iter;
    int dancers;
    int dance;
    int color[100] = {0};
    int order[100];
    int i,num,j;

    cin>>dancers>>dance;

    num = 3 * dance;

    for(i = 0; i < num; i++)
    {
        cin>>order[i];
    }
    for(i = 0; i < dance; i++)
    {
        if(i == 0)
            for(j = 0;j < group; j++)
            {
                base.push_back(j + 1);
                color[order[j]] = base[j];
            }
        else
        {
            tmp = base;
            for(j = i * group; j < (i + 1) * group; j++)
            {
                if(color[order[j]] != 0)
                {
                    iter = find(tmp.begin(),tmp.end(),color[order[j]]);
                    tmp.erase(iter);
                }
            }
            for(j = i * group; j < (1 + i) * group; j++)
            {
                int s = 0;
                if(color[order[j]] == 0)
                {
                    color[order[j]] = tmp[s++];
                }
            }
        }
    }
    for(i = 1; i <= dancers; i++)
    {
        cout<<color[i]<<" ";
    }
    return 0;
    //system("pause");
}


#include <iostream>
#include <vector>

using namespace std;

int main()
{
    vector<int> base,tmp;
    vector<int>::iterator iter;
    int dancers,dance,i,j,s;
    int color[10000]={0};
    int order[10000][3];

    cin>>dancers>>dance;

    for(i = 0; i < dance; i++)
    {
        for(j = 0; j < 3; j++)
        {
            cin>>order[i][j];
        }
        if(i == 0)
        {
            for(int k = 0; k < 3; k++)
            {
                base.push_back(k + 1);
                color[order[0][k]] = base[k];
            }
        }
        else
        {
            tmp = base;
            iter = tmp.begin();
            for(j = 0; j < 3; j++)
            {
                if(color[order[i][j]]!=0)
                {
                    iter += color[order[i][j]] - 1;
                    tmp.erase(iter);
                }

            }
            for(j = 0,s = 0; j < 3; j++)
            {
                if(color[order[i][j]] == 0)
                    color[order[i][j]] = tmp[s++];
            }

        }

    }
    for(i = 1; i <= dancers; i++)
        cout<<color[i]<<" ";
    return 0;

}


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
const int group = 3;

int main()
{
    vector<int> base;
    vector<int>::iterator iter;
    int dancers;
    int dance;
    int color[100] = {0};
    int order[100];
    int i,num,j;

    cin>>dancers>>dance;

    num = 3 * dance;

    for(i = 0; i < num; i++)
    {
        cin>>order[i];
    }
    for(i = 0; i < dance; i++)
    {
        if(i == 0)
            for(j = 0;j < group; j++)
            {
                base.push_back(j + 1);
                color[order[j]] = base[j];
            }
        else
        {
            vector<int> tmp(base);
            for(j = i * group; j < (i + 1) * group; j++)
            {
                if(color[order[j]] != 0)
                {
                    iter = find(tmp.begin(),tmp.end(),color[order[j]]);
                    tmp.erase(iter);
                }
            }
            for(j = i * group; j < (1 + i) * group; j++)
            {
                int s = 0;
                if(color[order[j]] == 0)
                {
                    color[order[j]] = tmp[s++];
                }
            }
        }
    }
    for(i = 1; i <= dancers; i++)
    {
        cout<<color[i]<<" ";
    }
    return 0;
    //system("pause");
}


#include <iostream>
#include <vector>

using namespace std;

int main()
{
    vector<int> base,tmp;
    vector<int>::iterator iter;
    int dancers,dance,i,j,s;
    int color[10000]={0};
    int order[10000][3];

    cin>>dancers>>dance;

    for(i = 0; i < dance; i++)
    {
        for(j = 0; j < 3; j++)
        {
            cin>>order[i][j];
        }
        if(i == 0)
        {
            for(int k = 0; k < 3; k++)
            {
                base.push_back(k + 1);
                color[order[0][k]] = base[k];
            }
        }
        else
        {
            tmp = base;
            iter = tmp.begin();
            for(j = 0; j < 3; j++)
            {
                if(color[order[i][j]]!=0)
                {
                    iter += color[order[i][j]] - 1;
                    tmp.erase(iter);
                }

            }
            for(j = 0,s = 0; j < 3; j++)
            {
                if(color[order[i][j]] == 0)
                    color[order[i][j]] = tmp[s++];
            }

        }

    }
    for(i = 1; i < dancers; i++)
        cout<<color[i]<<" ";
    return 0;

}


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
const int group = 3;

int main()
{
    vector<int> base;
    vector<int>::iterator iter;
    int dancers;
    int dance;
    int color[100] = {0};
    int order[100];
    int i,num,j;

    cin>>dancers>>dance;

    num = 3 * dance - 1;

    for(i = 0; i < num; i++)
    {
        scanf("%d",&order[i]);
    }
    for(i = 0; i < dance; i++)
    {
        if(i == 0)
            for(j = 0;j < group; j++)
            {
                base.push_back(j + 1);
                color[order[j]] = base[j];
            }
        else
        {
            vector<int> tmp(base);
            for(j = i * group; j < (i + 1) * group; j++)
            {
                if(color[order[j]] != 0)
                {
                    iter = find(tmp.begin(),tmp.end(),color[order[j]]);
                    tmp.erase(iter);
                }
            }
            for(j = i * group; j < (1 + i) * group; j++)
            {
                int s = 0;
                if(color[order[j]] == 0)
                {
                    color[order[j]] = tmp[s++];
                }
            }
        }
    }
    for(i = 0; i < dancers; i++)
    {
        cout<<color[i]<<" ";
    }
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int main()
{
    vector<int> base,tmp;
    vector<int>::iterator iter;
    int dancers,dance,i,j,s,a,b,c;
    long long int color[100010]={0};
    int order[3];

    cin>>dancers>>dance;

    for(i = 0; i < dance; i++)
    {
        cin>>order[0]>>order[1]>>order[2];
        if(i == 0)
        {
            for(int k = 0; k < 3; k++)
            {
                base.push_back(k + 1);
                color[order[k]] = base[k];
            }
        }
        else
        {
            tmp = base;
            iter = tmp.begin();
            for(j = 0; j < 3; j++)
            {
                if(color[order[j]]!=0)
                {
                    iter += color[order[j]] - 1;
                    tmp.erase(iter);
                }

            }
            for(j = 0,s = 0; j < 3; j++)
            {
                if(color[order[j]] == 0)
                    color[order[j]] = tmp[s++];
            }

        }

    }
    for(i = 1; i <= dancers; i++)
        cout<<color[i]<<" ";
    return 0;

}


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
const int group = 3;

int main()
{
    vector<int> base;
    vector<int>::iterator iter;
    int dancers;
    int dance;
    int color[100] = {0};
    int order[100];
    int i,num,j;

    cin>>dancers>>dance;
    num = 3 * dance - 1;

    for(i = 0; i < num; i++)
    {
        cin>>order[i];
    }
    for(i = 0; i < dance; i++)
    {
        if(i == 0)
            for(j = 0;j < group; j++)
            {
                base.push_back(j + 1);
                color[order[j]] = base[j];
            }
        else
        {
            vector<int> tmp(base);
            for(j = i * group; j < (i + 1) * group; j++)
            {
                if(color[order[j]] != 0)
                {
                    iter = find(tmp.begin(),tmp.end(),color[order[j]]);
                    tmp.erase(iter);
                }
            }
            for(j = i * dance; j < (group + i * dance); j++)
            {
                int s = 0;
                if(color[order[j]] == 0)
                {
                    color[order[j]] = tmp[s];
                }
            }
        }
    }
    for(i = 0; i < num; i++)
    {
        cout<<color[i]<<" ";
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string.h>
#include <queue>
#include <cstdio>
#include <vector>
using namespace std;

int main()
{
    int n,m,a,b,c;
    cin>>n>>m;
    int A[n+5];
    for(int i=0; i<=n+2; i++)A[i]=0;
    for(int i=1; i<=m; i++)
    {
        cin>>a>>b>>c;
        if(A[a]!=0)
        {
            if(A[a]==1){A[b]=2;A[c]=3;}
            else if(A[a]==3){A[b]=1;A[c]=2;}
            else{A[b]=1;A[c]=3;}
        }
        else if(A[b]!=0)
        {
            if(A[b]==1){A[a]=2;A[c]=3;}
            else if(A[b]==3){A[a]=1;A[c]=2;}
            else{A[a]=1;A[c]=3;}
        }
        else if(A[c]!=0)
        {
            if(A[c]==1){A[b]=2;A[a]=3;}
            else if(A[c]==3){A[b]=1;A[a]=2;}
            else{A[c]=1;A[a]=3;}
        }
        else{A[a]=1;A[b]=2;A[c]=3;}
    }
    cout<<A[1];
    for(int i=2; i<=n; i++)cout<<" "<<A[i];
    cout<<endl;
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string.h>
#include <queue>
#include <cstdio>
#include <vector>
using namespace std;

int main()
{
    int n,m,a,b,c,A[1005];
    cin>>n>>m;
    for(int i=0; i<=n+2; i++)A[i]=0;
    for(int i=1; i<=m; i++)
    {
        cin>>a>>b>>c;
        if(A[a]!=0)
        {
            if(A[a]==1){A[b]=2;A[c]=3;}
            else if(A[a]==3){A[b]=1;A[c]=2;}
            else{A[b]=1;A[c]=3;}
        }
        else if(A[b]!=0)
        {
            if(A[b]==1){A[a]=2;A[c]=3;}
            else if(A[b]==3){A[a]=1;A[c]=2;}
            else{A[a]=1;A[c]=3;}
        }
        else if(A[c]!=0)
        {
            if(A[c]==1){A[b]=2;A[a]=3;}
            else if(A[c]==3){A[b]=1;A[a]=2;}
            else{A[b]=1;A[a]=3;}
        }
        else{A[a]=1;A[b]=2;A[c]=3;}
    }
    cout<<A[1];
    for(int i=2; i<=n; i++)cout<<" "<<A[i];
    cout<<endl;
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string.h>
#include <queue>
#include <cstdio>
#include <vector>
using namespace std;

int main()
{
    int n,m,a,b,c;
    cin>>n>>m;
    int A[n+10];
    for(int i=0; i<=n+3; i++)A[i]=0;

    for(int i=1; i<=m; i++)
    {
        cin>>a>>b>>c;
        if(A[a]!=0)
        {
            if(A[a]==1){A[b]=2;A[c]=3;}
            else if(A[a]==3){A[b]=1;A[c]=2;}
            else{A[b]=1;A[c]=3;}
        }
        else if(A[b]!=0)
        {
            if(A[b]==1){A[a]=2;A[c]=3;}
            else if(A[b]==3){A[a]=1;A[c]=2;}
            else{A[a]=1;A[c]=3;}
        }
        else if(A[c]!=0)
        {
            if(A[c]==1){A[b]=2;A[a]=3;}
            else if(A[c]==3){A[b]=1;A[a]=2;}
            else{A[b]=1;A[a]=3;}
        }
        else{A[a]=1;A[b]=2;A[c]=3;}
    }
    cout<<A[1];
    for(int i=2; i<=n; i++)cout<<" "<<A[i];
    cout<<endl;
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string.h>
#include <queue>
#include <cstdio>
#include <vector>
using namespace std;

int main()
{
    int n,m,a,b,c,A[10005];
    cin>>n>>m;
    for(int i=0; i<=n+2; i++)A[i]=0;
    for(int i=1; i<=m; i++)
    {
        cin>>a>>b>>c;
        if(A[a]!=0)
        {
            if(A[a]==1){A[b]=2;A[c]=3;}
            else if(A[a]==3){A[b]=1;A[c]=2;}
            else{A[b]=1;A[c]=3;}
        }
        else if(A[b]!=0)
        {
            if(A[b]==1){A[a]=2;A[c]=3;}
            else if(A[b]==3){A[a]=1;A[c]=2;}
            else{A[a]=1;A[c]=3;}
        }
        else if(A[c]!=0)
        {
            if(A[c]==1){A[b]=2;A[a]=3;}
            else if(A[c]==3){A[b]=1;A[a]=2;}
            else{A[b]=1;A[a]=3;}
        }
        else{A[a]=1;A[b]=2;A[c]=3;}
    }
    cout<<A[1];
    for(int i=2; i<=n; i++)cout<<" "<<A[i];
    cout<<endl;
    return 0;
}


/* Author : Yashasvi girdhar
*/

/* Data Structure Includes */
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <bitset>
#include <stack>

/*other Includes */
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>

/* C Includes */
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;
typedef vector<int > vd;
typedef vector<long long int > vl;
typedef vector<bool > vb;
typedef vector<char > vc;
typedef vector<vd > vvd;

#define pb push_back
#define si(n) scanf("%d",&n)
#define sc(n) scanf("%c",&n)
#define ss(n) scanf("%s",n)
#define REP(i, n) for (int i = 0 ; i < (n) ; i ++)
#define all(a) a.begin(),a.end()
#define tr(container,it) for(typeof(container.begin()) it = container.begin() ; it != container.end() ; it++) //to traverse any container
#define present(container,element) (container.find(element)!=container.end()) //should be used for set,map etc.
#define vpresent(container,element) (find(all(container),element)!=container.end()) //should be used for vectors.
#define PI 3.14159265359
#define DegToRad(a) PI/180*a
#define RadToDeg(a) 180/PI*a

#define SIEVE(a) ({int b=ceil(sqrt(a));vd d(a,0);vd e;int f=2;e.pb(2);e.pb(3);for(int x=1;x<b+1;x++){for(int y=1;y<b+1;y++){int n=(4*x*x)+(y*y);if(n<=a&&(n%12==1||n%12==5)){d[n]^=1;}n=(3*x*x)+(y*y);if(n<=a&&n%12==7){d[n]^=1;}n=(3*x*x)-(y*y);if(x>y&&n<=a&&n%12==11){d[n]^=1;}}}for(int r=5;r<b+1;r++){if(d[r]){for(int i=r*r;i<a;i+=(r*r)){d[i]=0;}}}for(int c=5;c<a;c++){if(d[c]){e.pb(c);}}e;})

#define debug 1

int gcd(int a,int b){
	    if(b>a) return gcd(b,a);
	        return b==0?a:gcd(b,a%b);
}
void swap(int *m,int *n){
    int temp = *n;
    *n = *m;
    *m = temp;
}
struct sort_pred {
    bool operator()(const std::pair<int,int> &left, const std::pair<int,int> &right) {
        return left.first < right.first;
    }
};

int compare (const void *a, const void *b){
	const int *ia = (const int *)a; // casting pointer types
	const int *ib = (const int *)b;
	return *ia  - *ib;
}

list<int> *adj;
int n;

bool issafe(int x,int c,int a[]){
    list<int>::iterator it;
    tr(adj[x],it){
        if(a[*it] != -1 && c==a[*it])
            return false;
    }
    return true;
}

bool performdfs(int x,int a[]){
     // visited[x]=1;

    //cout<<x<<" ";

    for(int i=1;i<=3;i++){
        if(issafe(x,i,a)){
            a[x]=i;
        }
    }
    list<int>::iterator it;
    tr(adj[x],it){
        if(a[*it] == -1)
            performdfs(*it,a);
    }

    return false;
}

int main(){
    int m;
    scanf("%d %d",&n,&m);
    int a[n+1];
    for (int i = 0; i <= n; ++i)
        a[i]=-1;

    // int b[m];
    // REP(i,m)
    //     b[i]=-1;

    adj = new list<int>[n+1];

    REP(i,m){
        int t1, t2, t3;
        scanf("%d %d %d",&t1,&t2,&t3);
        adj[t1].push_back(t2);
        adj[t1].push_back(t3);
        adj[t2].push_back(t1);
        adj[t2].push_back(t3);
        adj[t3].push_back(t1);
        adj[t3].push_back(t2);
    }

    // bool visited[n+1];
    // memset(visited,false,sizeof(visited));

    for (int i = 1; i <= n; ++i)
    {
        if(a[i]==-1)
            bool ans = performdfs(i,a);
    // cout<<"ans= "<<ans<<endl;
    }
    for (int i = 1; i < n; ++i)
    {
        cout<<a[i]<<" ";
    }
    cout<<a[n]<<endl;
	return 0;
}


/* Author : Yashasvi girdhar
*/

/* Data Structure Includes */
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <bitset>
#include <stack>

/*other Includes */
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>

/* C Includes */
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;
typedef vector<int > vd;
typedef vector<long long int > vl;
typedef vector<bool > vb;
typedef vector<char > vc;
typedef vector<vd > vvd;

#define pb push_back
#define si(n) scanf("%d",&n)
#define sc(n) scanf("%c",&n)
#define ss(n) scanf("%s",n)
#define REP(i, n) for (int i = 0 ; i < (n) ; i ++)
#define all(a) a.begin(),a.end()
#define tr(container,it) for(typeof(container.begin()) it = container.begin() ; it != container.end() ; it++) //to traverse any container
#define present(container,element) (container.find(element)!=container.end()) //should be used for set,map etc.
#define vpresent(container,element) (find(all(container),element)!=container.end()) //should be used for vectors.
#define PI 3.14159265359
#define DegToRad(a) PI/180*a
#define RadToDeg(a) 180/PI*a

#define SIEVE(a) ({int b=ceil(sqrt(a));vd d(a,0);vd e;int f=2;e.pb(2);e.pb(3);for(int x=1;x<b+1;x++){for(int y=1;y<b+1;y++){int n=(4*x*x)+(y*y);if(n<=a&&(n%12==1||n%12==5)){d[n]^=1;}n=(3*x*x)+(y*y);if(n<=a&&n%12==7){d[n]^=1;}n=(3*x*x)-(y*y);if(x>y&&n<=a&&n%12==11){d[n]^=1;}}}for(int r=5;r<b+1;r++){if(d[r]){for(int i=r*r;i<a;i+=(r*r)){d[i]=0;}}}for(int c=5;c<a;c++){if(d[c]){e.pb(c);}}e;})

#define debug 1

int gcd(int a,int b){
	    if(b>a) return gcd(b,a);
	        return b==0?a:gcd(b,a%b);
}
void swap(int *m,int *n){
    int temp = *n;
    *n = *m;
    *m = temp;
}
struct sort_pred {
    bool operator()(const std::pair<int,int> &left, const std::pair<int,int> &right) {
        return left.first < right.first;
    }
};

int compare (const void *a, const void *b){
	const int *ia = (const int *)a; // casting pointer types
	const int *ib = (const int *)b;
	return *ia  - *ib;
}

int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    int a[n+1];
    for (int i = 0; i <= n; ++i)
        a[i]=-1;

    // int b[m];
    // REP(i,m)
    //     b[i]=-1;

    REP(i,m){
        int t1, t2, t3;
        scanf("%d %d %d",&t1,&t2,&t3);
        int count=0;

        if(a[t1]==-1)count++;
        if(a[t2]==-1)count++;
        if(a[t3]==-1)count++;

        if(count==3){
            // cout<<i<<" *3* "<<endl;
            a[t1]=1;
            a[t2]=2;
            a[t3]=3;
            continue;
        }
        else if(count==2){
            // cout<<i<<" *2* "<<endl;
            if(a[t1] != -1){
                // cout<<t1<<" "<<a[t1]<<endl;
                if(a[t1]+1 > 3)
                    a[t2] = (a[t1] + 2)%4 ;
                else
                    a[t2] = (a[t1] + 1);

                if(a[t1]+2 > 3)
                    a[t3] = (a[t1] + 3)%4 ;
                else
                    a[t3] = (a[t1] + 2);
            }
            else if(a[t2]!=-1){
                // cout<<t2<<" "<<a[t2]<<endl;
                if(a[t2]+1 > 3)
                    a[t1] = (a[t2] + 2)%4 ;
                else
                    a[t1] = (a[t2] + 1);

                if(a[t1]+2 > 3)
                    a[t3] = (a[t2] + 3)%4;
                else
                    a[t3] = (a[t2] + 2);
            }
            else if(a[t3]!=-1){
                // cout<<t3<<" "<<a[t3]<<endl;
                if(a[t1]+1 > 3)
                    a[t1] = (a[t3] + 2)%4 ;
                else
                    a[t1] = (a[t3] + 1);

                if(a[t1]+2 > 3)
                    a[t2] = (a[t3] + 3)%4;
                else
                    a[t2] = (a[t3] + 2);
            }

        }
        else if(count==1){
            // cout<<i<<" *1* "<<endl;
            if(a[t1]==-1){
                for (int i = 1; i <= 3; ++i){
                    if(a[t2] != i && a[t3] != i)
                        a[t1]=i;
                }
            }
            else if(a[t2]==-1){
                for (int i = 1; i <= 3; ++i){
                    if(a[t1] != i && a[t3] != i)
                        a[t2]=i;
                }
            }
            else if(a[t3]==-1){
                for (int i = 1; i <= 3; ++i){
                    if(a[t1] != i && a[t2] != i)
                        a[t3]=i;
                }
            }
        }
    }
    for (int i = 1; i <= n; ++i)
    {
        cout<<a[i]<<" ";
    }
    cout<<endl;
	return 0;
}


/* Author : Yashasvi girdhar
*/

/* Data Structure Includes */
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <bitset>
#include <stack>

/*other Includes */
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>

/* C Includes */
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;
typedef vector<int > vd;
typedef vector<long long int > vl;
typedef vector<bool > vb;
typedef vector<char > vc;
typedef vector<vd > vvd;

#define pb push_back
#define si(n) scanf("%d",&n)
#define sc(n) scanf("%c",&n)
#define ss(n) scanf("%s",n)
#define REP(i, n) for (int i = 0 ; i < (n) ; i ++)
#define all(a) a.begin(),a.end()
#define tr(container,it) for(typeof(container.begin()) it = container.begin() ; it != container.end() ; it++) //to traverse any container
#define present(container,element) (container.find(element)!=container.end()) //should be used for set,map etc.
#define vpresent(container,element) (find(all(container),element)!=container.end()) //should be used for vectors.
#define PI 3.14159265359
#define DegToRad(a) PI/180*a
#define RadToDeg(a) 180/PI*a

#define SIEVE(a) ({int b=ceil(sqrt(a));vd d(a,0);vd e;int f=2;e.pb(2);e.pb(3);for(int x=1;x<b+1;x++){for(int y=1;y<b+1;y++){int n=(4*x*x)+(y*y);if(n<=a&&(n%12==1||n%12==5)){d[n]^=1;}n=(3*x*x)+(y*y);if(n<=a&&n%12==7){d[n]^=1;}n=(3*x*x)-(y*y);if(x>y&&n<=a&&n%12==11){d[n]^=1;}}}for(int r=5;r<b+1;r++){if(d[r]){for(int i=r*r;i<a;i+=(r*r)){d[i]=0;}}}for(int c=5;c<a;c++){if(d[c]){e.pb(c);}}e;})

#define debug 1

int gcd(int a,int b){
	    if(b>a) return gcd(b,a);
	        return b==0?a:gcd(b,a%b);
}
void swap(int *m,int *n){
    int temp = *n;
    *n = *m;
    *m = temp;
}
struct sort_pred {
    bool operator()(const std::pair<int,int> &left, const std::pair<int,int> &right) {
        return left.first < right.first;
    }
};

int compare (const void *a, const void *b){
	const int *ia = (const int *)a; // casting pointer types
	const int *ib = (const int *)b;
	return *ia  - *ib;
}

list<int> *adj;
int n;

bool issafe(int x,int c,int a[]){
    list<int>::iterator it;
    tr(adj[x],it){
        if(a[*it] != -1 && c==a[*it])
            return false;
    }
    return true;
}

bool performdfs(int x,int a[]){
    // visited[x]=1;
    if(x==n+1)
        return true;
    // cout<<x<<" ";

    for(int i=1;i<=3;i++){
        if(issafe(x,i,a)){
            a[x]=i;
        }
    }
    list<int>::iterator it;
    tr(adj[x],it){
        if(a[*it] == -1)
            performdfs(*it,a);
    }

    return false;
}

int main(){
    int m;
    scanf("%d %d",&n,&m);
    int a[n+1];
    for (int i = 0; i <= n; ++i)
        a[i]=-1;

    // int b[m];
    // REP(i,m)
    //     b[i]=-1;

    adj = new list<int>[n+1];

    REP(i,m){
        int t1, t2, t3;
        scanf("%d %d %d",&t1,&t2,&t3);
        adj[t1].push_back(t2);
        adj[t1].push_back(t3);
        adj[t2].push_back(t1);
        adj[t2].push_back(t3);
        adj[t3].push_back(t1);
        adj[t3].push_back(t2);
    }

    // bool visited[n+1];
    // memset(visited,false,sizeof(visited));

    bool ans = performdfs(1,a);
    // cout<<"ans= "<<ans<<endl;

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


/* Author : Yashasvi girdhar
*/

/* Data Structure Includes */
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <bitset>
#include <stack>

/*other Includes */
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>

/* C Includes */
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;
typedef vector<int > vd;
typedef vector<long long int > vl;
typedef vector<bool > vb;
typedef vector<char > vc;
typedef vector<vd > vvd;

#define pb push_back
#define si(n) scanf("%d",&n)
#define sc(n) scanf("%c",&n)
#define ss(n) scanf("%s",n)
#define REP(i, n) for (int i = 0 ; i < (n) ; i ++)
#define all(a) a.begin(),a.end()
#define tr(container,it) for(typeof(container.begin()) it = container.begin() ; it != container.end() ; it++) //to traverse any container
#define present(container,element) (container.find(element)!=container.end()) //should be used for set,map etc.
#define vpresent(container,element) (find(all(container),element)!=container.end()) //should be used for vectors.
#define PI 3.14159265359
#define DegToRad(a) PI/180*a
#define RadToDeg(a) 180/PI*a

#define SIEVE(a) ({int b=ceil(sqrt(a));vd d(a,0);vd e;int f=2;e.pb(2);e.pb(3);for(int x=1;x<b+1;x++){for(int y=1;y<b+1;y++){int n=(4*x*x)+(y*y);if(n<=a&&(n%12==1||n%12==5)){d[n]^=1;}n=(3*x*x)+(y*y);if(n<=a&&n%12==7){d[n]^=1;}n=(3*x*x)-(y*y);if(x>y&&n<=a&&n%12==11){d[n]^=1;}}}for(int r=5;r<b+1;r++){if(d[r]){for(int i=r*r;i<a;i+=(r*r)){d[i]=0;}}}for(int c=5;c<a;c++){if(d[c]){e.pb(c);}}e;})

#define debug 1

int gcd(int a,int b){
	    if(b>a) return gcd(b,a);
	        return b==0?a:gcd(b,a%b);
}
void swap(int *m,int *n){
    int temp = *n;
    *n = *m;
    *m = temp;
}
struct sort_pred {
    bool operator()(const std::pair<int,int> &left, const std::pair<int,int> &right) {
        return left.first < right.first;
    }
};

int compare (const void *a, const void *b){
	const int *ia = (const int *)a; // casting pointer types
	const int *ib = (const int *)b;
	return *ia  - *ib;
}

list<int> *adj;
int n;

bool issafe(int x,int c,int a[]){
    list<int>::iterator it;
    tr(adj[x],it){
        if(c==a[*it])
            return false;
    }
    return true;
}

bool performdfs(int x,int a[],bool visited[]){
    // visited[x]=1;
    if(x==n+1)
        return true;
    // cout<<x<<" ";

    for(int i=1;i<=3;i++){
        if(issafe(x,i,a)){
            a[x]=i;
            if(performdfs(x+1,a,visited))
                return true;

            // a[x]=-1;
        }
    }

    return false;
}

int main(){
    int m;
    scanf("%d %d",&n,&m);
    int a[n+1];
    for (int i = 0; i <= n; ++i)
        a[i]=-1;

    // int b[m];
    // REP(i,m)
    //     b[i]=-1;

    adj = new list<int>[n+1];

    REP(i,m){
        int t1, t2, t3;
        scanf("%d %d %d",&t1,&t2,&t3);
        adj[t1].push_back(t2);
        adj[t1].push_back(t3);
        adj[t2].push_back(t1);
        adj[t2].push_back(t3);
        adj[t3].push_back(t1);
        adj[t3].push_back(t2);
    }

    bool visited[n+1];
    memset(visited,false,sizeof(visited));

    performdfs(1,a,visited);

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


/* Author : Yashasvi girdhar
*/

/* Data Structure Includes */
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <bitset>
#include <stack>

/*other Includes */
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>

/* C Includes */
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;
typedef vector<int > vd;
typedef vector<long long int > vl;
typedef vector<bool > vb;
typedef vector<char > vc;
typedef vector<vd > vvd;

#define pb push_back
#define si(n) scanf("%d",&n)
#define sc(n) scanf("%c",&n)
#define ss(n) scanf("%s",n)
#define REP(i, n) for (int i = 0 ; i < (n) ; i ++)
#define all(a) a.begin(),a.end()
#define tr(container,it) for(typeof(container.begin()) it = container.begin() ; it != container.end() ; it++) //to traverse any container
#define present(container,element) (container.find(element)!=container.end()) //should be used for set,map etc.
#define vpresent(container,element) (find(all(container),element)!=container.end()) //should be used for vectors.
#define PI 3.14159265359
#define DegToRad(a) PI/180*a
#define RadToDeg(a) 180/PI*a

#define SIEVE(a) ({int b=ceil(sqrt(a));vd d(a,0);vd e;int f=2;e.pb(2);e.pb(3);for(int x=1;x<b+1;x++){for(int y=1;y<b+1;y++){int n=(4*x*x)+(y*y);if(n<=a&&(n%12==1||n%12==5)){d[n]^=1;}n=(3*x*x)+(y*y);if(n<=a&&n%12==7){d[n]^=1;}n=(3*x*x)-(y*y);if(x>y&&n<=a&&n%12==11){d[n]^=1;}}}for(int r=5;r<b+1;r++){if(d[r]){for(int i=r*r;i<a;i+=(r*r)){d[i]=0;}}}for(int c=5;c<a;c++){if(d[c]){e.pb(c);}}e;})

#define debug 1

int gcd(int a,int b){
	    if(b>a) return gcd(b,a);
	        return b==0?a:gcd(b,a%b);
}
void swap(int *m,int *n){
    int temp = *n;
    *n = *m;
    *m = temp;
}
struct sort_pred {
    bool operator()(const std::pair<int,int> &left, const std::pair<int,int> &right) {
        return left.first < right.first;
    }
};

int compare (const void *a, const void *b){
	const int *ia = (const int *)a; // casting pointer types
	const int *ib = (const int *)b;
	return *ia  - *ib;
}

list<int> *adj;
int n;

bool issafe(int x,int c,int a[]){
    list<int>::iterator it;
    tr(adj[x],it){
        if(c==a[*it])
            return false;
    }
    return true;
}

bool performdfs(int x,int a[],bool visited[]){
    // visited[x]=1;
    if(x==n+1)
        return true;
    // cout<<x<<" ";

    for(int i=1;i<=3;i++){
        if(issafe(x,i,a)){
            a[x]=i;
            if(performdfs(x+1,a,visited))
                return true;

            a[x]=-1;
        }
    }

    return false;
}

int main(){
    int m;
    scanf("%d %d",&n,&m);
    int a[n+1];
    for (int i = 0; i <= n; ++i)
        a[i]=-1;

    // int b[m];
    // REP(i,m)
    //     b[i]=-1;

    adj = new list<int>[n+1];

    REP(i,m){
        int t1, t2, t3;
        scanf("%d %d %d",&t1,&t2,&t3);
        adj[t1].push_back(t2);
        adj[t1].push_back(t3);
        adj[t2].push_back(t1);
        adj[t2].push_back(t3);
        adj[t3].push_back(t1);
        adj[t3].push_back(t2);
    }

    bool visited[n+1];
    memset(visited,false,sizeof(visited));

    performdfs(1,a,visited);

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


/* Author : Yashasvi girdhar
*/

/* Data Structure Includes */
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <bitset>
#include <stack>

/*other Includes */
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>

/* C Includes */
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;
typedef vector<int > vd;
typedef vector<long long int > vl;
typedef vector<bool > vb;
typedef vector<char > vc;
typedef vector<vd > vvd;

#define pb push_back
#define si(n) scanf("%d",&n)
#define sc(n) scanf("%c",&n)
#define ss(n) scanf("%s",n)
#define REP(i, n) for (int i = 0 ; i < (n) ; i ++)
#define all(a) a.begin(),a.end()
#define tr(container,it) for(typeof(container.begin()) it = container.begin() ; it != container.end() ; it++) //to traverse any container
#define present(container,element) (container.find(element)!=container.end()) //should be used for set,map etc.
#define vpresent(container,element) (find(all(container),element)!=container.end()) //should be used for vectors.
#define PI 3.14159265359
#define DegToRad(a) PI/180*a
#define RadToDeg(a) 180/PI*a

#define SIEVE(a) ({int b=ceil(sqrt(a));vd d(a,0);vd e;int f=2;e.pb(2);e.pb(3);for(int x=1;x<b+1;x++){for(int y=1;y<b+1;y++){int n=(4*x*x)+(y*y);if(n<=a&&(n%12==1||n%12==5)){d[n]^=1;}n=(3*x*x)+(y*y);if(n<=a&&n%12==7){d[n]^=1;}n=(3*x*x)-(y*y);if(x>y&&n<=a&&n%12==11){d[n]^=1;}}}for(int r=5;r<b+1;r++){if(d[r]){for(int i=r*r;i<a;i+=(r*r)){d[i]=0;}}}for(int c=5;c<a;c++){if(d[c]){e.pb(c);}}e;})

#define debug 1

int gcd(int a,int b){
	    if(b>a) return gcd(b,a);
	        return b==0?a:gcd(b,a%b);
}
void swap(int *m,int *n){
    int temp = *n;
    *n = *m;
    *m = temp;
}
struct sort_pred {
    bool operator()(const std::pair<int,int> &left, const std::pair<int,int> &right) {
        return left.first < right.first;
    }
};

int compare (const void *a, const void *b){
	const int *ia = (const int *)a; // casting pointer types
	const int *ib = (const int *)b;
	return *ia  - *ib;
}

list<int> *adj;
int n;

bool issafe(int x,int c,int a[]){
    list<int>::iterator it;
    tr(adj[x],it){
        if(a[*it] != -1 && c==a[*it])
            return false;
    }
    return true;
}

bool performdfs(int x,int a[]){
    // visited[x]=1;
    if(x==n+1)
        return true;
    // cout<<x<<" ";

    for(int i=1;i<=3;i++){
        if(issafe(x,i,a)){
            a[x]=i;
            if(performdfs(x+1,a))
                return true;

            // a[x]=-1;
        }
    }

    return false;
}

int main(){
    int m;
    scanf("%d %d",&n,&m);
    int a[n+1];
    for (int i = 0; i <= n; ++i)
        a[i]=-1;

    // int b[m];
    // REP(i,m)
    //     b[i]=-1;

    adj = new list<int>[n+1];

    REP(i,m){
        int t1, t2, t3;
        scanf("%d %d %d",&t1,&t2,&t3);
        adj[t1].push_back(t2);
        adj[t1].push_back(t3);
        adj[t2].push_back(t1);
        adj[t2].push_back(t3);
        adj[t3].push_back(t1);
        adj[t3].push_back(t2);
    }

    // bool visited[n+1];
    // memset(visited,false,sizeof(visited));

    bool ans = performdfs(1,a);
    // cout<<"ans= "<<ans<<endl;

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


/* Author : Yashasvi girdhar
*/

/* Data Structure Includes */
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <bitset>
#include <stack>

/*other Includes */
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>

/* C Includes */
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;
typedef vector<int > vd;
typedef vector<long long int > vl;
typedef vector<bool > vb;
typedef vector<char > vc;
typedef vector<vd > vvd;

#define pb push_back
#define si(n) scanf("%d",&n)
#define sc(n) scanf("%c",&n)
#define ss(n) scanf("%s",n)
#define REP(i, n) for (int i = 0 ; i < (n) ; i ++)
#define all(a) a.begin(),a.end()
#define tr(container,it) for(typeof(container.begin()) it = container.begin() ; it != container.end() ; it++) //to traverse any container
#define present(container,element) (container.find(element)!=container.end()) //should be used for set,map etc.
#define vpresent(container,element) (find(all(container),element)!=container.end()) //should be used for vectors.
#define PI 3.14159265359
#define DegToRad(a) PI/180*a
#define RadToDeg(a) 180/PI*a

#define SIEVE(a) ({int b=ceil(sqrt(a));vd d(a,0);vd e;int f=2;e.pb(2);e.pb(3);for(int x=1;x<b+1;x++){for(int y=1;y<b+1;y++){int n=(4*x*x)+(y*y);if(n<=a&&(n%12==1||n%12==5)){d[n]^=1;}n=(3*x*x)+(y*y);if(n<=a&&n%12==7){d[n]^=1;}n=(3*x*x)-(y*y);if(x>y&&n<=a&&n%12==11){d[n]^=1;}}}for(int r=5;r<b+1;r++){if(d[r]){for(int i=r*r;i<a;i+=(r*r)){d[i]=0;}}}for(int c=5;c<a;c++){if(d[c]){e.pb(c);}}e;})

#define debug 1

int gcd(int a,int b){
	    if(b>a) return gcd(b,a);
	        return b==0?a:gcd(b,a%b);
}
void swap(int *m,int *n){
    int temp = *n;
    *n = *m;
    *m = temp;
}
struct sort_pred {
    bool operator()(const std::pair<int,int> &left, const std::pair<int,int> &right) {
        return left.first < right.first;
    }
};

int compare (const void *a, const void *b){
	const int *ia = (const int *)a; // casting pointer types
	const int *ib = (const int *)b;
	return *ia  - *ib;
}

list<int> *adj;
int n;

bool issafe(int x,int c,int a[]){
    list<int>::iterator it;
    tr(adj[x],it){
        if(a[*it] != -1 && c==a[*it])
            return false;
    }
    return true;
}

bool performdfs(int x,int a[]){
    // visited[x]=1;
    if(x==n+1)
        return true;
    // cout<<x<<" ";

    for(int i=1;i<=3;i++){
        if(issafe(x,i,a)){
            a[x]=i;
            if(performdfs(x+1,a))
                return true;

            // a[x]=-1;
        }
    }

    return false;
}

int main(){
    int m;
    scanf("%d %d",&n,&m);
    int a[n+1];
    for (int i = 0; i <= n; ++i)
        a[i]=-1;

    // int b[m];
    // REP(i,m)
    //     b[i]=-1;

    adj = new list<int>[n+1];

    REP(i,m){
        int t1, t2, t3;
        scanf("%d %d %d",&t1,&t2,&t3);
        adj[t1].push_back(t2);
        adj[t1].push_back(t3);
        adj[t2].push_back(t1);
        adj[t2].push_back(t3);
        adj[t3].push_back(t1);
        adj[t3].push_back(t2);
    }

    // bool visited[n+1];
    // memset(visited,false,sizeof(visited));

    bool ans = performdfs(1,a);
    cout<<"ans= "<<ans<<endl;

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


#include <iostream>

using namespace std;

int main()
{
    long n,m, color[10000]={0},x,y,z,c[4];
    cin>>n>>m;
    for (int i=1; i<=m; i++)
    {
        cin>>x>>y>>z;
        for( int j=1; j<=3; j++) c[j]=0;
        c[color[x]]=1; c[color[y]]=1; c[color[z]]=1;
        if (color[x]==0) {for( int j=1; j<=3; j++) if(c[j]==0) {color[x]=j; c[j]=1; break;}}
        if (color[y]==0) {for( int j=1; j<=3; j++) if(c[j]==0) {color[y]=j; c[j]=1; break;}}
        if (color[z]==0) {for( int j=1; j<=3; j++) if(c[j]==0) {color[z]=j; c[j]=1; break;}}
    }
    for (int i=1; i<=n; i++)
        cout<<color[i]<<" ";
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    long n,m, color[15000]={0},x,y,z,c[4];
    cin>>n>>m;
    for (int i=1; i<=m; i++)
    {
        cin>>x>>y>>z;
        for( int j=1; j<=3; j++) c[j]=0;
        c[color[x]]=1; c[color[y]]=1; c[color[z]]=1;
        if (color[x]==0) {for( int j=1; j<=3; j++) if(c[j]==0) {color[x]=j; c[j]=1; break;}}
        if (color[y]==0) {for( int j=1; j<=3; j++) if(c[j]==0) {color[y]=j; c[j]=1; break;}}
        if (color[z]==0) {for( int j=1; j<=3; j++) if(c[j]==0) {color[z]=j; c[j]=1; break;}}
    }
    for (int i=1; i<=n; i++)
        cout<<color[i]<<" ";
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    long n,m, color[200000]={0},x,y,z,c[4];
    cin>>n>>m;
    for (long i=1; i<=m; i++)
    {
        cin>>x>>y>>z;
        for( long j=1; j<=3; j++) c[j]=0;
        c[color[x]]=1; c[color[y]]=1; c[color[z]]=1;
        if (color[x]==0) {for( long j=1; j<=3; j++) if(c[j]==0) {color[x]=j; c[j]=1; break;}}
        if (color[y]==0) {for( long j=1; j<=3; j++) if(c[j]==0) {color[y]=j; c[j]=1; break;}}
        if (color[z]==0) {for( long j=1; j<=3; j++) if(c[j]==0) {color[z]=j; c[j]=1; break;}}
    }
    for (long i=1; i<=n; i++)
        cout<<color[i]<<" ";
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    long n,m, color[100000]={0},x,y,z,c[4];
    cin>>n>>m;
    for (long i=1; i<=m; i++)
    {
        cin>>x>>y>>z;
        for( long j=1; j<=3; j++) c[j]=0;
        c[color[x]]=1; c[color[y]]=1; c[color[z]]=1;
        if (color[x]==0) {for( long j=1; j<=3; j++) if(c[j]==0) {color[x]=j; c[j]=1; break;}}
        if (color[y]==0) {for( long j=1; j<=3; j++) if(c[j]==0) {color[y]=j; c[j]=1; break;}}
        if (color[z]==0) {for( long j=1; j<=3; j++) if(c[j]==0) {color[z]=j; c[j]=1; break;}}
    }
    for (long i=1; i<=n; i++)
        cout<<color[i]<<" ";
    return 0;
}


using namespace std;
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<bitset>
#include<map>
#include<set>
#include<climits>
#include<algorithm>
#include<utility>
#include<cstdlib>
#include<cctype>
#include<queue>
#include<sstream>
#include<cassert>
#define read(x) scanf("%d",&x)
#define write(x) printf("%d\n",x)
#define assign(x,n) x=(int*)calloc(n,4)
#define rep(i,n) for(i=1;i<=n;++i)
#define max(a,b) ((a)>(b))?(a):(b)
typedef  long long int ull;
typedef pair<int,int> pr;

int d[100001][3]={{0}};
int klr[100001]={0};

int fn(int i)
{
	int col,p=-1;

	if(klr[d[i][0]])p=0;
	else if(klr[d[i][1]])p=1;
	else if(klr[d[i][2]])p=2;

	if(p==-1){
		p=0;
		klr[d[i][0]]=1;
	}

	swap(d[i][0],d[i][p]);
	col=klr[d[i][0]];

	if(col==3){klr[d[i][1]]=1;klr[d[i][2]]=2;}
    if(col==2)
	{
	klr[d[i][1]]=1;
	klr[d[i][2]]=3;
    }
    if(col==1){klr[d[i][1]]=2;klr[d[i][2]]=3;}

}

int main()
{
//freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
int n,m,i,j,k,a,b,c;
read(n);read(m);
for(i=0;i<m;i++)
cin>>d[i][0]>>d[i][1]>>d[i][2];

klr[d[0][0]]=1;

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

for(i=1;i<=n;i++)
{
if(i!=1)cout<<" ";
if(!klr[i])klr[i]=1;
cout<<klr[i];
}
cout<<endl;

return 0;
}


using namespace std;
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<bitset>
#include<map>
#include<set>
#include<climits>
#include<algorithm>
#include<utility>
#include<cstdlib>
#include<cctype>
#include<queue>
#include<sstream>
#include<cassert>
#define read(x) scanf("%d",&x)
#define write(x) printf("%d\n",x)
#define assign(x,n) x=(int*)calloc(n,4)
#define rep(i,n) for(i=1;i<=n;++i)
#define max(a,b) ((a)>(b))?(a):(b)
typedef  long long int ull;
typedef pair<int,int> pr;

int d[100001][3]={{0}};
int klr[100001]={0};

int fn(int i)
{
	int col,p;

	if(klr[d[i][0]])p=0;
	else if(klr[d[i][1]])p=1;
	else if(klr[d[i][2]])p=2;

	swap(d[i][0],d[i][p]);
	col=klr[d[i][0]];

	if(col==3){klr[d[i][1]]=1;klr[d[i][2]]=2;}
    if(col==2)
	{
	klr[d[i][1]]=1;
	klr[d[i][2]]=3;
    }
    if(col==1){klr[d[i][1]]=2;klr[d[i][2]]=3;}

}

int main()
{
//freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
int n,m,i,j,k,a,b,c;
read(n);read(m);
for(i=0;i<m;i++)
cin>>d[i][0]>>d[i][1]>>d[i][2];

klr[d[0][0]]=1;

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

for(i=1;i<=n;i++)
{
if(i!=1)cout<<" ";
if(!klr[i])klr[i]=1;
cout<<klr[i];
}

return 0;
}


using namespace std;
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<bitset>
#include<map>
#include<set>
#include<climits>
#include<algorithm>
#include<utility>
#include<cstdlib>
#include<cctype>
#include<queue>
#include<sstream>
#include<cassert>
#define read(x) scanf("%d",&x)
#define write(x) printf("%d\n",x)
#define assign(x,n) x=(int*)calloc(n,4)
#define rep(i,n) for(i=1;i<=n;++i)
#define max(a,b) ((a)>(b))?(a):(b)
typedef  long long int ull;
typedef pair<int,int> pr;

int d[100001][3]={{0}};
int klr[100001]={0};

int fn(int i)
{
	int col,p;

	if(klr[d[i][0]])p=0;
	else if(klr[d[i][1]])p=1;
	else if(klr[d[i][2]])p=2;

	swap(d[i][0],d[i][p]);
	col=klr[d[i][0]];
	if(col==3){klr[d[i][1]]=1;klr[d[i][2]]=2;}
    if(col==2)
	{
	klr[d[i][1]]=1;
	klr[d[i][2]]=3;
   }
    if(col==1){klr[d[i][1]]=2;klr[d[i][2]]=3;}

}

int main()
{
//freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
int n,m,i,j,k,a,b,c;
read(n);read(m);
for(i=0;i<m;i++)
cin>>d[i][0]>>d[i][1]>>d[i][2];

klr[d[0][0]]=1;

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

for(i=1;i<=n;i++)
{
if(i!=1)cout<<" ";
cout<<klr[i];
}

return 0;
}


using namespace std;
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<bitset>
#include<map>
#include<set>
#include<climits>
#include<algorithm>
#include<utility>
#include<cstdlib>
#include<cctype>
#include<queue>
#include<sstream>
#include<cassert>
#define read(x) scanf("%d",&x)
#define write(x) printf("%d\n",x)
#define assign(x,n) x=(int*)calloc(n,4)
#define rep(i,n) for(i=1;i<=n;++i)
#define max(a,b) ((a)>(b))?(a):(b)
typedef  long long int ull;
typedef pair<int,int> pr;

int d[100001][3]={{0}};
int klr[100001]={0};

int fn(int i)
{
	int col,p=-1;

	if(klr[d[i][0]])p=0;
	else if(klr[d[i][1]])p=1;
	else if(klr[d[i][2]])p=2;

	if(p==-1){
		p=0;
		col[d[i][0]]=1;
	}

	swap(d[i][0],d[i][p]);
	col=klr[d[i][0]];

	if(col==3){klr[d[i][1]]=1;klr[d[i][2]]=2;}
    if(col==2)
	{
	klr[d[i][1]]=1;
	klr[d[i][2]]=3;
    }
    if(col==1){klr[d[i][1]]=2;klr[d[i][2]]=3;}

}

int main()
{
//freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
int n,m,i,j,k,a,b,c;
read(n);read(m);
for(i=0;i<m;i++)
cin>>d[i][0]>>d[i][1]>>d[i][2];

klr[d[0][0]]=1;

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

for(i=1;i<=n;i++)
{
if(i!=1)cout<<" ";
if(!klr[i])klr[i]=1;
cout<<klr[i];
}
cout<<endl;

return 0;
}


using namespace std;
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<bitset>
#include<map>
#include<set>
#include<climits>
#include<algorithm>
#include<utility>
#include<cstdlib>
#include<cctype>
#include<queue>
#include<sstream>
#include<cassert>
#define read(x) scanf("%d",&x)
#define write(x) printf("%d\n",x)
#define assign(x,n) x=(int*)calloc(n,4)
#define rep(i,n) for(i=1;i<=n;++i)
#define max(a,b) ((a)>(b))?(a):(b)
typedef  long long int ull;
typedef pair<int,int> pr;

int d[100001][3]={{0}};
int klr[100001]={0};

int fn(int i)
{
	int col,p;

	if(klr[d[i][0]])p=0;
	else if(klr[d[i][1]])p=1;
	else if(klr[d[i][2]])p=2;

	swap(d[i][0],d[i][p]);
	col=klr[d[i][0]];

	if(col==3){klr[d[i][1]]=1;klr[d[i][2]]=2;}
    if(col==2)
	{
	klr[d[i][1]]=1;
	klr[d[i][2]]=3;
    }
    if(col==1){klr[d[i][1]]=2;klr[d[i][2]]=3;}

}

int main()
{
//freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
int n,m,i,j,k,a,b,c;
read(n);read(m);
for(i=0;i<m;i++)
cin>>d[i][0]>>d[i][1]>>d[i][2];

klr[d[0][0]]=1;

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

for(i=1;i<=n;i++)
{
if(i!=1)cout<<" ";
if(!klr[i])klr[i]=1;
cout<<klr[i];
}
cout<<endl;

return 0;
}


#include<iostream>
#include<cstdlib>
#include<cctype>
#include<cstdio>
#include<bitset>
#include<deque>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<list>

using namespace std;

#define PI 3.14159265359
#define E 2.71828182846
typedef vector<int> vi;
typedef vector<vi>vvi;
typedef map<int,int>mii;
typedef set<int> si;
typedef pair<int,int>ii;
typedef vector<ii>vii;
#define DFS_WHITE -1
#define DFS_BLACK 1
#define GRAY 0

vector<vii>adjlist;

int main()
{
    int n,m;
    cin>>n>>m;
    int col[n+1];
    int cont[n+1];
     memset(col,0,sizeof col);
   //memset(cont,0,sizeof cont);
    int arr[m][3];
    for(int i=0;i<m;i++)
    {
        cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
       // cont[arr[i][0]]++;
       // cont[arr[i][1]]++;
        //cont[arr[i][2]]++;
    }
   // sort(cont+1,cont+n+1);
   col[arr[0][0]]=1;
   col[arr[0][1]]=2;
   col[arr[0][2]]=3;
    for(int i=1;i<m;i++)

        if(col[arr[i][0]]==0&&col[arr[i][1]]==0&&col[arr[i][2]]==0)
        {
            col[arr[i][0]]=1;
            col[arr[i][1]]=2;
            col[arr[i][2]]=3;

        }
        else  if(col[arr[i][0]]!=0&&col[arr[i][1]]==0&&col[arr[i][2]]==0)
        {
            int l,k=col[arr[i][0]];
            if(k==1){
                col[arr[i][1]]=2;
              col[arr[i][2]]=3;
            }
            else if(k==2){col[arr[i][1]]=1;
            col[arr[i][2]]=3;}

               else if(k==3){col[arr[i][1]]=1;
            col[arr[i][2]]=2;}

       }
       else  if(col[arr[i][0]]==0&&col[arr[i][1]]!=0&&col[arr[i][2]]==0)
        {
            int l,k=col[arr[i][1]];
            if(k==1){
                col[arr[i][0]]=2;
              col[arr[i][2]]=3;
            }
            else if(k==2){col[arr[i][0]]=1;
            col[arr[i][2]]=3;}

               else if(k==3){col[arr[i][0]]=1;
            col[arr[i][2]]=2;}
        }
        else  if(col[arr[i][0]]==0&&col[arr[i][1]]==0&&col[arr[i][2]]!=0)
        {
            int l,k=col[arr[i][1]];
            if(k==1){
                col[arr[i][0]]=2;
              col[arr[i][1]]=3;
            }
            else if(k==2){col[arr[i][0]]=1;
            col[arr[i][1]]=3;}

               else if(k==3){col[arr[i][0]]=1;
            col[arr[i][1]]=2;}

       }
       else{
            if(col[arr[i][0]]!=0&&col[arr[i][1]]!=0&&col[arr[i][2]]==0)
            {
                int k=col[arr[i][0]];
                int l=col[arr[i][1]];
                if(abs(k-l)==2)
                    col[arr[i][2]]=2;
                else
                    col[arr[i][2]]=3;
            }
            else if(col[arr[i][0]]==0&&col[arr[i][1]]!=0&&col[arr[i][2]]!=0)
            {
                int k=col[arr[i][1]];
                int l=col[arr[i][2]];
                if(abs(k-l)==2)
                    col[arr[i][0]]=2;
                else
                    col[arr[i][0]]=3;
            }
            else if(col[arr[i][0]]!=0&&col[arr[i][1]]==0&&col[arr[i][2]]!=0)
            {
                int k=col[arr[i][0]];
                int l=col[arr[i][2]];
                if(abs(k-l)==2)
                    col[arr[i][1]]=2;
                else
                    col[arr[i][1]]=3;
            }
       /*     else if(col[arr[i][0]]!=0&&col[arr[i][1]]!=0&&col[arr[i][2]]!=0)
            {
                int k=col[arr[i][0]];
                int l=col[arr[i][1]];
                int m=col[arr[i][2]];
                if(abs(k-l)==m || abs(k-m)==l || abs(l-m)==k)
                continue;
                else
                {
                   // cout<<"chutiya kat gaya\n";
                   // return 0;
                }
            }
            */

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

    return 0;
}