#include<bits/stdc++.h>
#define LL long long
#define LD long double
#define ull unsigned long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(), (x).end()
#define fio ios::sync_with_stdio(false); cin.tie(0);

using namespace std;

const int N = 1e5 + 7;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000000007;
const double eps = 1e-8;
const double PI = acos(-1);

template<class T, class S> inline void add(T& a, S b) {a += b; if(a >= mod) a -= mod;}
template<class T, class S> inline void sub(T& a, S b) {a -= b; if(a < 0) a += mod;}
template<class T, class S> inline bool chkmax(T& a, S b) {return a < b ? a = b, true : false;}
template<class T, class S> inline bool chkmin(T& a, S b) {return a > b ? a = b, true : false;}

int n, m;
char s[N];
int cnt[26];

struct SegmentTree {
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
    int sum[N << 2], lazy[N << 2];
    inline void pull(int rt) {
        sum[rt] = sum[rt << 1] + sum[rt << 1 | 1];
    }
    inline void push(int rt, int l, int r) {
        if(~lazy[rt]) {
            int mid = l + r >> 1;
            sum[rt << 1] = lazy[rt] * (mid - l + 1);
            sum[rt << 1 | 1] = lazy[rt] * (r - mid);
            lazy[rt << 1] = lazy[rt];
            lazy[rt << 1 | 1] = lazy[rt];
            lazy[rt] = -1;
        }
    }
    void build(char c, int l, int r,  int rt) {
        lazy[rt] = -1;
        if(l == r) {
            sum[rt] = s[l] == c;
            return;
        }
        int mid = l + r >> 1;
        build(c, lson); build(c, rson);
        pull(rt);
    }
    void update(int L, int R, int val, int l, int r, int rt) {
        if(R < l || r < L || R < L) return;
        if(L <= l && r <= R) {
            sum[rt] = val * (r - l + 1);
            lazy[rt] = val;
            return;
        }
        push(rt, l, r);
        int mid = l + r >> 1;
        update(L, R, val, lson);
        update(L, R, val, rson);
        pull(rt);
    }
    int query(int L, int R, int l, int r, int rt) {
        if(R < l || r < L || R < L) return 0;
        if(L <= l && r <= R) return sum[rt];
        push(rt, l, r);
        int mid = l + r >> 1;
        return query(L, R, lson) + query(L, R, rson);
    }
} Tree[26];

int main() {
    scanf("%d%d", &n, &m);
    scanf("%s", s + 1);
    for(int i = 0; i < 26; i++) Tree[i].build(i + 'a', 1, n, 1);
    while(m--) {
        int L, R; scanf("%d%d", &L, &R);
        for(int i = 0; i < 26; i++) cnt[i] = Tree[i].query(L, R, 1, n, 1);
        int odd = -1;
        bool can = true;
        for(int i = 0; i < 26; i++) {
            if(cnt[i] & 1) {
                if(~odd) {
                    can = false;
                    break;
                } else odd = i;
            }
        }
        if(can) {
            for(int i = 0; i < 26; i++) Tree[i].update(L, R, 0, 1, n, 1);
            if(~odd) Tree[odd].update(L + R >> 1, L + R >> 1, 1, 1, n, 1), cnt[odd]--;
            int be = L, ed = R;
            for(int i = 0; i < 26; i++) {
                cnt[i] >>= 1;
                Tree[i].update(be, be + cnt[i] - 1, 1, 1, n, 1);
                Tree[i].update(ed - cnt[i] + 1, ed, 1, 1, n, 1);
                be += cnt[i];
                ed -= cnt[i];
            }
        }
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 0; j < 26; j++) {
            if(Tree[j].query(i, i, 1, n, 1)) {
                s[i] = 'a' + j;
                break;
            }
        }
    }
    puts(s + 1);
    return 0;
}

/*

*/


#include<bits/stdc++.h>
#define LL long long
#define LD long double
#define ull unsigned long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(), (x).end()
#define fio ios::sync_with_stdio(false); cin.tie(0);

using namespace std;

const int N = 1e5 + 7;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000000007;
const double eps = 1e-8;
const double PI = acos(-1);

template<class T, class S> inline void add(T& a, S b) {a += b; if(a >= mod) a -= mod;}
template<class T, class S> inline void sub(T& a, S b) {a -= b; if(a < 0) a += mod;}
template<class T, class S> inline bool chkmax(T& a, S b) {return a < b ? a = b, true : false;}
template<class T, class S> inline bool chkmin(T& a, S b) {return a > b ? a = b, true : false;}

int n, m;
char s[N];
int cnt[26];

struct SegmentTree {
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
    int sum[N << 2], lazy[N << 2];
    inline void pull(int rt) {
        sum[rt] = sum[rt << 1] + sum[rt << 1 | 1];
    }
    inline void push(int rt, int l, int r) {
        if(~lazy[rt]) {
            int mid = l + r >> 1;
            sum[rt << 1] = lazy[rt] * (mid - l + 1);
            sum[rt << 1 | 1] = lazy[rt] * (r - mid);
            lazy[rt << 1] = lazy[rt];
            lazy[rt << 1 | 1] = lazy[rt];
            lazy[rt] = -1;
        }
    }
    void build(char c, int l, int r,  int rt) {
        lazy[rt] = -1;
        if(l == r) {
            sum[rt] = s[l] == c;
            return;
        }
        int mid = l + r >> 1;
        build(c, lson); build(c, rson);
        pull(rt);
    }
    void update(int L, int R, int val, int l, int r, int rt) {
        if(R < l || r < L || R < L) return;
        if(L <= l && r <= R) {
            sum[rt] = val * (r - l + 1);
            lazy[rt] = val;
            return;
        }
        push(rt, l, r);
        int mid = l + r >> 1;
        update(L, R, val, lson);
        update(L, R, val, rson);
        pull(rt);
    }
    int query(int L, int R, int l, int r, int rt) {
        if(R < l || r < L || R < L) return 0;
        if(L <= l && r <= R) return sum[rt];
        push(rt, l, r);
        int mid = l + r >> 1;
        return query(L, R, lson) + query(L, R, rson);
    }
} Tree[26];

int main() {
    scanf("%d%d", &n, &m);
    scanf("%s", s + 1);
    for(int i = 0; i < 26; i++) Tree[i].build(i + 'a', 1, n, 1);
    while(m--) {
        int L, R; scanf("%d%d", &L, &R);
        for(int i = 0; i < 26; i++) cnt[i] = Tree[i].query(L, R, 1, n, 1);
        int odd = -1;
        bool can = true;
        for(int i = 0; i < 26; i++) {
            if(cnt[i] & 1) {
                if(~odd) {
                    can = false;
                    break;
                } else odd = i;
            }
        }
        if(can) {
            for(int i = 0; i < 26; i++) Tree[i].update(L, R, 0, 1, n, 1);
            if(~odd) Tree[odd].update(L + R >> 1, L + R >> 1, 1, 1, n, 1), cnt[odd]--;
            int be = L, ed = R;
            for(int i = 0; i < 26; i++) {
                cnt[i] >>= 1;
                Tree[i].update(be, be + cnt[i] - 1, 1, 1, n, 1);
                Tree[i].update(ed - cnt[i] + 1, ed, 1, 1, n, 1);
                be += cnt[i];
                ed -= cnt[i];
            }
        }
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 0; j < 26; j++) {
            if(Tree[j].query(i, i, 1, n, 1)) {
                s[i] = 'a' + j;
                break;
            }
        }
    }
    puts(s + 1);
    return 0;
}

/*
*/


#include<bits/stdc++.h>
#define LL long long
#define LD long double
#define ull unsigned long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(), (x).end()
#define fio ios::sync_with_stdio(false); cin.tie(0);

using namespace std;

const int N = 1e5 + 7;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000000007;
const double eps = 1e-8;
const double PI = acos(-1);

template<class T, class S> inline void add(T& a, S b) {a += b; if(a >= mod) a -= mod;}
template<class T, class S> inline void sub(T& a, S b) {a -= b; if(a < 0) a += mod;}
template<class T, class S> inline bool chkmax(T& a, S b) {return a < b ? a = b, true : false;}
template<class T, class S> inline bool chkmin(T& a, S b) {return a > b ? a = b, true : false;}

int n, m;
char s[N];
int cnt[26];

struct SegmentTree {
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
    int sum[N << 2], lazy[N << 2];
    inline void pull(int rt) {
        sum[rt] = sum[rt << 1] + sum[rt << 1 | 1];
    }
    inline void push(int rt, int l, int r) {
        if(~lazy[rt]) {
            int mid = l + r >> 1;
            sum[rt << 1] = lazy[rt] * (mid - l + 1);
            sum[rt << 1 | 1] = lazy[rt] * (r - mid);
            lazy[rt << 1] = lazy[rt];
            lazy[rt << 1 | 1] = lazy[rt];
            lazy[rt] = -1;
        }
    }
    void build(char c, int l, int r,  int rt) {
        lazy[rt] = -1;
        if(l == r) {
            sum[rt] = s[l] == c;
            return;
        }
        int mid = l + r >> 1;
        build(c, lson); build(c, rson);
        pull(rt);
    }
    void update(int L, int R, int val, int l, int r, int rt) {
        if(R < l || r < L || R < L) return;
        if(L <= l && r <= R) {
            sum[rt] = val * (r - l + 1);
            lazy[rt] = val;
            return;
        }
        push(rt, l, r);
        int mid = l + r >> 1;
        update(L, R, val, lson);
        update(L, R, val, rson);
        pull(rt);
    }
    int query(int L, int R, int l, int r, int rt) {
        if(R < l || r < L || R < L) return 0;
        if(L <= l && r <= R) return sum[rt];
        push(rt, l, r);
        int mid = l + r >> 1;
        return query(L, R, lson) + query(L, R, rson);
    }
} Tree[26];

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    scanf("%d%d", &n, &m);
    scanf("%s", s + 1);
    for(int i = 0; i < 26; i++) Tree[i].build(i + 'a', 1, n, 1);
    while(m--) {
        int L, R; scanf("%d%d", &L, &R);
        for(int i = 0; i < 26; i++) cnt[i] = Tree[i].query(L, R, 1, n, 1);
        int odd = -1;
        bool can = true;
        for(int i = 0; i < 26; i++) {
            if(cnt[i] & 1) {
                if(~odd) {
                    can = false;
                    break;
                } else odd = i;
            }
        }
        if(can) {
            for(int i = 0; i < 26; i++) Tree[i].update(L, R, 0, 1, n, 1);
            if(~odd) Tree[odd].update(L + R >> 1, L + R >> 1, 1, 1, n, 1), cnt[odd]--;
            int be = L, ed = R;
            for(int i = 0; i < 26; i++) {
                cnt[i] >>= 1;
                Tree[i].update(be, be + cnt[i] - 1, 1, 1, n, 1);
                Tree[i].update(ed - cnt[i] + 1, ed, 1, 1, n, 1);
                be += cnt[i];
                ed -= cnt[i];
            }
        }
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 0; j < 26; j++) {
            if(Tree[j].query(i, i, 1, n, 1)) {
                s[i] = 'a' + j;
                break;
            }
        }
    }
    puts(s + 1);
    return 0;
}

/*
*/


# include <bits/stdc++.h>

using namespace std;

const int maxn = 1e5 + 100;
const int maxk = 26 ;

int n, seg[4 * maxn][maxk], lzy[4 * maxn];

void pull(int, int, int);
void push(int);

void add(int c,int l,int r,int L=0,int R=n,int id=1){
	if(l == L && r == R){
		memset(seg[id], 0, sizeof seg[id]);
		seg[id][c] = R - L;
		lzy[id] = c;
		return;
	}
	pull(id, L, R);
	int mid = (L + R) >> 1;
	if(l < mid)
		add(c, l, min(mid, r), L, mid, id * 2 + 0);
	if(r > mid)
		add(c, max(l, mid), r, mid, R, id * 2 + 1);
	push(id);
}

int get(int c,int l,int r,int L=0,int R=n,int id=1){
	if(l == L && r == R)
		return seg[id][c];
	pull(id, L, R);
	int mid = (L + R) >> 1, ret = 0;
	if(l < mid)
		ret += get(c, l, min(mid, r), L, mid, id * 2 + 0);
	if(r > mid)
		ret += get(c, max(l, mid), r, mid, R, id * 2 + 1);
	return ret;
}

void push(int id){
	for (int i = 0; i < 26; i++)
		seg[id][i] = seg[id * 2 + 0][i] + seg[id * 2 + 1][i];
}

void pull(int id,int L,int R){
	if(lzy[id] == -1)
		return;
	int mid = (L + R) >> 1;
	add(lzy[id], L, mid, L, mid, id * 2 + 0);
	add(lzy[id], mid, R, mid, R, id * 2 + 1);
	lzy[id] = -1;
}

void modify(int l,int r){
	int let[26];
	for (int i = 0; i < 26; i++)
		let[i] = get(i, l, r);

	int cnt = 0;
	for (int i = 0; i < 26; i++)
		cnt += (let[i] % 2);

	if(cnt > 1)
		return;

	int idx = -1;
	for (int i = 0; i < 26; i++)
		if(let[i] % 2)
			idx = i, let[i]--;

	for (int i = 0; i < 26; i++)
		if(let[i] % 2 == 0 && let[i] > 0){
			int shift = let[i] / 2;
			add(i, l, l + shift);
			add(i, r - shift, r);
			l += shift, r -= shift;
		}

	if(idx != -1)
		add(idx, l, r);
}

int main(){
	ifstream fin ("input.txt");
	ofstream fout ("output.txt");

	int q;
	fin >> n >> q;
	for (int i = 0; i < n; i++){
		char k; fin >> k;
		add(k - 'a', i, i + 1);
	}

	for (int i = 0; i < q; i++){
		int l, r;
		fin >> l >> r;
		l--;
		modify(l, r);
	}

	for (int i = 0; i < n; i++)
		for (int j = 0; j < 26; j++)
			if(get(j, i, i + 1) == 1)
				fout << char(j + 'a');
	fout << endl;

	return 0;
}


import java.util.Scanner;

public class Flagi1 {

	public static void main(String[] args) {
		Scanner con = new Scanner(System.in);
		int b = con.nextInt();
		int [] mass;
		int i,x,y,z;
		mass = new int [b];
		int a = con.nextInt();
		for (i=0;i<b;++i){
			mass[i]=-1;
		}
		for (i=0; i < a; ++i){
			x = con.nextInt();
			y = con.nextInt();
			z = con.nextInt();
			if ((mass[x-1]==-1)|(mass[y-1]==-1)|(mass[z-1]==-1)){
				mass[x-1]=0;
				mass[y-1]=1;
				mass[z-1]=2;
			}
			else if (mass[x-1]!=-1){
				mass[y-1]=(mass[x-1]+1)%3;
				mass[z-1]=(mass[x-1]+2)%3;
			}
			else if (mass[y-1]!=-1){
				mass[x-1]=(mass[x-1]+1)%3;
				mass[z-1]=(mass[x-1]+2)%3;
			}
			else if (mass[z-1]!=-1){
				mass[y-1]=(mass[x-1]+1)%3;
				mass[x-1]=(mass[x-1]+2)%3;
			}
		}
		for (i=0;i<b;++i){
			System.out.println((mass[i] +1));
		}
		// TODO Auto-generated method stub

	}

}


import java.util.Scanner;

public class pro {
	public static void main(String[] args) {
		int i = 0;
		int j = 0;
		int y = 0;
		int z = 0;
		Scanner con = new Scanner(System.in);
		int k = con.nextInt();
		int N = con.nextInt();
		int [] [] mass;
		mass = new int[N][3];
		for (i=0;i<N;++i){
			for (j=0;j<3;++j){
				mass [i][j] = con.nextInt();
			}
		}

		for (y=0;y<3;++y){
			for (j=0;j<3;++j){
				for (i=1;i<N;++i){
					for (z=i-1;z>=0; z = z- 1){
						if (mass[i][j] == mass[z][y]){
							mass[i][j] = mass[i][y];
							mass[i][y] = mass[z][y];
						}

					}
			}
			}
		}
		y = 0;
		while (y<k){
		for (i=0;i<N;++i){
			for (j=0;j<3;++j){
				if (mass[i][j]==(y+1)){
					System.out.println((j+1));

					y +=1;
			}
		}

}

	}
	}
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

public class B {

    static BufferedReader in;
    static StringTokenizer st;
    static PrintWriter out;

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

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

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

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

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
                System.out)));
        int n = nextInt();
        int m = nextInt();
        Map<Integer, Integer> map = new HashMap<>();
        int[] ans = new int[n + 1];
        for (int i = 1; i <= m; i++) {
            int[] c = new int[4];
            int[] dancer = new int[4];
            for (int j = 1; j <= 3; j++) {
                dancer[j] = nextInt();
            }
            for (int j = 1; j <= 3; j++) {
                if (map.get(dancer[j]) != null) {
                    c[map.get(dancer[j])] = 1;
                }
            }
            for (int j = 1; j <= 3; j++) {
                if (map.get(dancer[j]) == null) {
                    for (int k = 1; k <= 3; k++) {
                        if (c[k] == 0) {
                            map.put(dancer[j], k);
                            ans[dancer[j]] = k;
                            c[k] = 1;
                            break;
                        }
                    }
                }
            }
        }
        for (int i = 1; i <= n; i++) {
            out.print(ans[i] + " ");
        }
        out.close();
    }
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

public class B {

    static BufferedReader in;
    static StringTokenizer st;
    static PrintWriter out;

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

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

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

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

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
                System.out)));
        int n = nextInt();
        int m = nextInt();
        Map<Integer, Integer> map = new HashMap<>();
        int[] ans = new int[n + 1];
        for (int i = 1; i <= m; i++) {
            int[] c = new int[4];
            for (int j = 1; j <= 3; j++) {
                int dancer = nextInt();
                if (map.get(dancer) == null) {
                    for (int k = 1; k <= 3; k++) {
                        if (c[k] == 0) {
                            map.put(dancer, k);
                            ans[dancer] = k;
                            c[k] = 1;
                            break;
                        }
                    }
                } else {
                    c[map.get(dancer)] = 1;
                    continue;
                }
            }
        }
        for (int i = 1; i <= n; i++) {
            out.print(ans[i] + " ");
        }
        out.close();
    }
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    private static final InputStreamReader standardInput = new InputStreamReader(System.in);
    private static final BufferedReader bufferedReader = new BufferedReader(standardInput);
    private static final Scanner scanner = new Scanner(bufferedReader);

    private static final OutputStreamWriter standardOutput = new OutputStreamWriter(System.out);
    private static final BufferedWriter bufferedWriter = new BufferedWriter(standardOutput);
    private static final PrintWriter printWriter = new PrintWriter(bufferedWriter);

    public static void main(String[] args) {
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        Dance[] dances = new Dance[n];
        for (int i = 0; i < m; i++) {
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            int c = scanner.nextInt();
            dances[i] = new Dance(a, b, c);
        }
        int[] colors = getColors(n, m, dances);
        for (int i = 0; i < n; i++) {
            printWriter.print(colors[i] + " ");
        }
        printWriter.flush();
        scanner.close();
    }

    private static int[] getColors(int n, int m, Dance[] dances) {
        int[] colors = new int[n];
        for (int i = 0; i < m; i++) {
            if (colors[dances[i].getA() - 1] == 0) {
                colors[dances[i].getA() - 1] = assignColor(colors[dances[i].getB() - 1], colors[dances[i].getC() - 1]);
            }
            if (colors[dances[i].getB() - 1] == 0) {
                colors[dances[i].getB() - 1] = assignColor(colors[dances[i].getA() - 1], colors[dances[i].getC() - 1]);
            }
            if (colors[dances[i].getC() - 1] == 0) {
                colors[dances[i].getC() - 1] = assignColor(colors[dances[i].getA() - 1], colors[dances[i].getB() - 1]);
            }
        }
        return colors;
    }

    private static int assignColor(int a, int b) {
        if (a != 1 && b != 1) {
            return 1;
        } else if (a == 1 && b == 3) {
            return 2;
        } else if (a == 1 && b == 2) {
            return 3;
        } else if (a == 2 && b == 1) {
            return 3;
        } else if (a == 3 && b == 1) {
            return 2;
        } else {
            return 2;
        }
    }
}

class Dance {

    int a, b, c;

    public Dance(int a, int b, int c) {
        this.a = a;
        this.b = b;
        this.c = c;
    }

    public int getA() {
        return this.a;
    }

    public int getB() {
        return this.b;
    }

    public int getC() {
        return this.c;
    }
}


/**
 * Created with IntelliJ IDEA.
 * User: IAIN
 * Date: 6/11/13
 * Time: 5:43 PM
 * To change this template use File | Settings | File Templates.
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class FlagDay {
    void solve() throws IOException {
        int n = getInt();
        int m = getInt();
        int [] dancers = new int[n + 1];
        Arrays.fill(dancers, -1);
        for(int i = 0; i < m; ++i){
            int a = getInt();
            int b = getInt();
            int c = getInt();
            int d = -1;
            if(dancers[a]!=-1)d = dancers[a];
            if(dancers[b]!=-1)d = dancers[b];
            if(dancers[c]!=-1)d = dancers[c];
            if(d == -1){
                dancers[a] = 1;
                dancers[b] = 2;
                dancers[c] = 3;
            }
            else{
                int e = -1;
                int f = -1;
                if(d == 1){e = 2; f = 3;}
                if(d == 2){e = 1; f = 3;}
                if(d == 3){e = 1; f = 2;}
                if(dancers[a]==d){dancers[b]=e;dancers[c]=f;}
                if(dancers[b]==d){dancers[a]=e;dancers[c]=f;}
                if(dancers[c]==d){dancers[a]=e;dancers[b]=f;}
            }
        }
        for(int i = 1; i < dancers.length; ++i){
            System.out.print(dancers[i] + " ");
        }
    }

    BufferedReader bufferedReader;
    PrintWriter output;
    StringTokenizer tokenizer;

    public static void main(String[] args) throws IOException {
        FlagDay contest = new FlagDay();
        contest.run();
    }

    public String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(bufferedReader.readLine());
        }
        return tokenizer.nextToken();
    }

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

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

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

    void run() throws IOException {
        bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        output = new PrintWriter(System.out);
        solve();
    }
}


import java.io.*;

public class B{

    public static void main(String[] args) throws IOException{
        BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
        String ss1[] = s.readLine().split(" ");
        int n = Integer.parseInt(ss1[0]);
        int m = Integer.parseInt(ss1[1]);
        int [] arr = new int[n];
        int a, b, c;
        for(int i = 0; i < m; i++){
            ss1 = s.readLine().split(" ");
            a = Integer.parseInt(ss1[0]);
            b = Integer.parseInt(ss1[1]);
            c = Integer.parseInt(ss1[2]);
            if((arr[a-1] > 0 && arr[a-1] != 1)|| (arr[b-1] > 0 && arr[b-1] != 2) || (arr[c-1] > 0 && arr[c-1] != 3)){
                if(arr[a-1] == 2){
                        arr[b-1] = 3;
                        arr[c-1] = 1;
                }
                else if(arr[a-1] == 3){
                        arr[b-1] = 1;
                        arr[c-1] = 2;
                }
                else if(arr[b-1] == 3){
                        arr[a-1] = 2;
                        arr[c-1] = 1;
                }
                else if(arr[b-1] == 1){
                        arr[a-1] = 3;
                        arr[c-1] = 2;
                }
                else if(arr[c-1] == 1){
                        arr[b-1] = 3;
                        arr[a-1] = 2;
                }
                else if(arr[c-1] == 2){
                        arr[b-1] = 1;
                        arr[a-1] = 3;
                }
            }
            else{
                arr[a-1] = 1;
                arr[b-1] = 2;
                arr[c-1] = 3;
            }
        }
        for(int i = 0; i < n-1; i++)
            System.out.print(arr[i] + " ");
        System.out.print(arr[n-1]);

    }
}


import java.util.Scanner;

public class B {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();

		int[] c = new int[n];
		for(int i = 0; i < m; ++i) {
			int d1 = sc.nextInt()-1;
			int d2 = sc.nextInt()-1;
			int d3 = sc.nextInt()-1;

			if(c[d1] != 0) {
				c[d2] = (c[d1]+1)%3+1;
				c[d3] = (c[d2]+1)%3+1;
			} else if(c[d2] != 0) {
				c[d3] = (c[d2]+1)%3+1;
				c[d1] = (c[d3]+1)%3+1;
			} else if(c[d3] != 0) {
				c[d1] = (c[d3]+1)%3+1;
				c[d2] = (c[d1]+1)%3+1;
			} else {
				c[d1] = 1;
				c[d2] = 2;
				c[d3] = 3;
			}
		}
		for(int i = 0; i < n; ++i) {
			if(i != 0)
				System.out.print(" ");
			System.out.print(c[i]);
		}
		System.out.println();
	}
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class B {
	static int[] n;
	static int[] m;
	static int[][] d;
	static ArrayList<ArrayList<Integer>> p;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int nc = sc.nextInt();
		int mc = sc.nextInt();

		n = new int[nc];
		m = new int[mc];
		Arrays.fill(m, 15);
		p = new ArrayList();
		d = new int[mc][3];

		for(int i = 0; i < nc; ++i)
			p.add(new ArrayList());

		for(int i = 0; i < mc; ++i)
			for(int j = 0; j < 3; ++j) {
				int s = sc.nextInt()-1;
				p.get(s).add(i);
				d[i][j] = s;
			}

		while(true) {
			int i;
			for(i = 0; i < mc; ++i)
				if(m[i] != 0)
					break;
			if(i == mc)
				break;
			color(i);
		}

		for(int i = 0; i < nc; ++i) {
			if(i != 0)
				System.out.print(" ");
			System.out.print(n[i]/2);
		}
		System.out.println();
	}

	static void color(int b) {
		int i;
		for(i = 0; i < 3; ++i)
			if(n[d[b][i]] == 0)
				break;

		int alt = 15;
		for(int k : p.get(d[b][i])) {
			int l = Math.min(m[k], alt);
			int h = Math.max(alt, m[k]);
			if(l != h) {
				if(l <= 7 || h == 15)
					alt = l;
				else {
					if(l+4 == h)
						alt = 5;
					else if(h == 12)
						alt = 7;
					else if(h == 10)
						alt = 3;
				}
			}
		}
		if(alt == 12)
			alt = 5;
		else if(alt > 7)
			alt = 3;

		n[d[b][i]] = alt;
		for(int k : p.get(d[b][i]))
			if(m[k] > 0)
				m[k] -= alt;
	}
}


import java.util.*;

public class Problem_B{
    public static int[] missingColors(int presentColor){

        int[] a = new int[2];
        if (presentColor == 1){
            a[0] = 2;
            a[1] = 3;
        } else if (presentColor == 2){
            a[0] = 1;
            a[1] = 3;
        } else {
            a[0] = 1;
            a[1] = 2;
        }
        return a;
    }

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] ans = new int[n];

        for (int i = 0; i < n; i++){
            ans[i] = 0;
        }

        int m = sc.nextInt();

        for (int i = 0; i < m; i++){
            int first = sc.nextInt();
            int second = sc.nextInt();
            int third = sc.nextInt();

            if (ans[first - 1] != 0){
                int[] a = missingColors(ans[first - 1]);
                ans[second - 1] = a[0];
                ans[third - 1] = a[1];
            } else if (ans[second - 1] != 0){
                int[] a = missingColors(ans[second - 1]);
                ans[first - 1] = a[0];
                ans[third - 1] = a[1];
            } else if (ans[third - 1] != 0){
                int[] a = missingColors(ans[third - 1]);
                ans[first - 1] = a[0];
                ans[second - 1] = a[1];
            } else {
                ans[first - 1] = 1;
                ans[second - 1] = 2;
                ans[third - 1] = 3;
            }
        }

        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < n; i++){
            sb.append(ans[i] + " ");
        }

        String  answer = sb.toString();
        answer = answer.substring(0, answer.length() - 1);
        System.out.println(answer);
    }
}


/**
 * Date: 15.10.13
 *
 * @author Margarita Markina
 */
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class A {
    public void solve() throws Exception {
        int n = nextInt();
        int m = nextInt();
        T[] ar = new T[m];
        for(int i = 0; i < m; i++) {
            T a = new T(nextInt(), nextInt(), nextInt());
            ar[i] = a;
        }
        int cl[] = new int[n];
        for(int i = 0; i < m ; i++) {
            boolean one = true;
            boolean two = true;
            boolean three = true;
            T t = ar[i];
            int a = (int)t.a;
            int b = (int)t.b;
            int c = (int)t.c;
            a--;
            b--;
            c--;
            if(cl[a] == 1 || cl[b] == 1 || cl[c] == 1)
                one = false;
            if(cl[a] == 2 || cl[b] == 2 || cl[c] == 2)
                two = false;
            if(cl[a] == 3 || cl[b] == 3 || cl[c] == 3)
                three = false;
            if(cl[a] == 0) {
                if(one) {
                    cl[a] = 1;
                    one = false;
                } else
                if(two) {
                    cl[a] = 2;
                    two = false;
                } else
                if(three) {
                    cl[a] = 3;
                    three = false;
                }
            }
            if(cl[b] == 0) {
                if(one) {
                    cl[b] = 1;
                    one = false;
                } else
                if(two) {
                    cl[b] = 2;
                    two = false;
                } else
                if(three) {
                    cl[b] = 3;
                    three = false;
                }
            }
            if(cl[c] == 0) {
                if(one) {
                    cl[c] = 1;
                    one = false;
                } else
                if(two) {
                    cl[c] = 2;
                    two = false;
                } else
                if(three) {
                    cl[c] = 3;
                    three = false;
                }
            }
        }
        for(int i = 0; i < n; i++) {
            out.print(cl[i] + " ");
        }

    }
    public static void main(String[] args) throws Exception {
        A problem = new A();
        problem.solve();
        problem.close();
    }

    BufferedReader in;
    PrintWriter out;
    String curLine;
    StringTokenizer tok;
    final String delimeter = " ";
    final String endOfFile = "";

    public A(BufferedReader in, PrintWriter out) throws Exception {
        this.in = in;
        this.out = out;
        curLine = in.readLine();
        if (curLine == null || curLine == endOfFile) {
            tok = null;
        } else {
            tok = new StringTokenizer(curLine, delimeter);
        }
    }

    public A() throws Exception {
        this(new BufferedReader(new InputStreamReader(System.in)),
                new PrintWriter(System.out));
    }

    public A(String filename) throws Exception {
        this(new BufferedReader(new FileReader(filename + ".in")),
                new PrintWriter(filename + ".out"));
    }

    public boolean hasMore() throws Exception {
        if (tok == null || curLine == null) {
            return false;
        } else {
            while (!tok.hasMoreTokens()) {
                curLine = in.readLine();
                if (curLine == null || curLine.equalsIgnoreCase(endOfFile)) {
                    tok = null;
                    return false;
                } else {
                    tok = new StringTokenizer(curLine);
                }
            }
            return true;
        }
    }

    public String nextWord() throws Exception {
        if (!hasMore()) {
            return null;
        } else {
            return tok.nextToken();
        }
    }

    public int nextInt() throws Exception {
        return Integer.parseInt(nextWord());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextWord());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextWord());
    }

    public int[] readIntArray(int n) throws Exception {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = nextInt();
        }
        return res;
    }

    public void close() throws Exception {
        in.close();
        out.close();
    }

    private class T<A,B,C> {
        private A a;
        private B b;
        private C c;

        public T(A a, B b, C c) {
            super();
            this.a = a;
            this.b = b;
            this.c = c;
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class B {

  public static void main(String[] args) {
    solve(new InputReader(System.in));
  }

  static int[] colors;

  static void solve(InputReader in) {
    int n = in.ni();
    int m = in.ni();
    colors = new int[n + 1];

    for (int i = 0; i < m; i++) {
      int[] dancers = new int[] {in.ni(), in.ni(), in.ni()};
      if (!chooseColor(dancers)) {
        for (int j = 0; j < 3; j++) {
          colors[dancers[j]] = j + 1;
        }
      }
    }

    StringBuilder builder = new StringBuilder();
    for (int i = 1; i <= n; i++) {
      builder.append(colors[i] + " ");
    }
    System.out.println(builder);
  }

  static boolean chooseColor(int[] dancers) {
    for (int i = 0; i < 3; i++) {
      if (colors[dancers[i]] != 0) {
        colors[dancers[(i + 1) % 3]] = colors[dancers[i]] % 3 + 1;
        colors[dancers[(i + 2) % 3]] = (colors[dancers[i]] + 1) % 3 + 1;
        return true;
      }
    }
    return false;
  }

  static class InputReader {
    BufferedReader br;
    StringTokenizer st;

    InputReader(InputStream stream) {
      br = new BufferedReader(new InputStreamReader(stream));
    }

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

    int ni() {
      return Integer.parseInt(next());
    }

    long nl() {
      return Long.parseLong(next());
    }

    int[] na(int n) {
      int[] arr = new int[n];
      for (int i = 0; i < n; i++) {
        arr[i] = ni();
      }
      return arr;
    }
  }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class B {

  public static void main(String[] args) {
    solve(new InputReader(System.in));
  }

  static int[] colors;

  static void solve(InputReader in) {
    int n = in.ni();
    int m = in.ni();
    colors = new int[n + 1];

    out: for (int i = 0; i < m; i++) {
      int[] dancers = new int[] {in.ni(), in.ni(), in.ni()};

      for (int j = 0; j < 3; j++) {
        if (colors[dancers[j]] != 0) {
          colors[dancers[(j + 1) % 3]] = colors[dancers[j]] % 3 + 1;
          colors[dancers[(j + 2) % 3]] = (colors[dancers[j]] + 1) % 3 + 1;
          continue out;
        }
      }

      for (int j = 0; j < 3; j++) {
        colors[dancers[j]] = j + 1;
      }
    }

    StringBuilder builder = new StringBuilder();
    for (int i = 1; i <= n; i++) {
      builder.append(colors[i] + " ");
    }
    System.out.println(builder);
  }

  static class InputReader {
    BufferedReader br;
    StringTokenizer st;

    InputReader(InputStream stream) {
      br = new BufferedReader(new InputStreamReader(stream));
    }

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

    int ni() {
      return Integer.parseInt(next());
    }

    long nl() {
      return Long.parseLong(next());
    }

    int[] na(int n) {
      int[] arr = new int[n];
      for (int i = 0; i < n; i++) {
        arr[i] = ni();
      }
      return arr;
    }
  }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class B {

  public static void main(String[] args) {
    solve(new InputReader(System.in));
  }

  static void solve(InputReader in) {
    int n = in.ni();
    int m = in.ni();
    int[] colors = new int[n + 1];

    out: for (int i = 0; i < m; i++) {
      int[] dancers = new int[] {in.ni(), in.ni(), in.ni()};

      for (int j = 0; j < 3; j++) {
        if (colors[dancers[j]] != 0) {
          colors[dancers[(j + 1) % 3]] = colors[dancers[j]] % 3 + 1;
          colors[dancers[(j + 2) % 3]] = (colors[dancers[j]] + 1) % 3 + 1;
          continue out;
        }
      }

      for (int j = 0; j < 3; j++) {
        colors[dancers[j]] = j + 1;
      }
    }

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

  static class InputReader {
    BufferedReader br;
    StringTokenizer st;

    InputReader(InputStream stream) {
      br = new BufferedReader(new InputStreamReader(stream));
    }

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

    int ni() {
      return Integer.parseInt(next());
    }

    long nl() {
      return Long.parseLong(next());
    }

    int[] na(int n) {
      int[] arr = new int[n];
      for (int i = 0; i < n; i++) {
        arr[i] = ni();
      }
      return arr;
    }
  }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class FlagDay {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        int N = sc.nextInt();
        int M = sc.nextInt();

        Integer[] dancers = new Integer[N + 1];
        for (int i = 0; i < M; i++) {
        	int d1 = sc.nextInt();
        	int d2 = sc.nextInt();
        	int d3 = sc.nextInt();
        	if (dancers[d1] != null) {
        		LinkedList<Integer> lst = make3();
        		lst.remove(dancers[d1]);
        		dancers[d2] = lst.removeFirst();
        		dancers[d3] = lst.removeFirst();
        	} else if (dancers[d2] != null) {
        		LinkedList<Integer> lst = make3();
        		lst.remove(dancers[d2]);
        		dancers[d1] = lst.removeFirst();
        		dancers[d3] = lst.removeFirst();
        	} else if (dancers[d3] != null) {
        		LinkedList<Integer> lst = make3();
        		lst.remove(dancers[d3]);
        		dancers[d1] = lst.removeFirst();
        		dancers[d2] = lst.removeFirst();
        	} else {
        		dancers[d1] = 1;
        		dancers[d2] = 2;
        		dancers[d3] = 3;
        	}
        }

        StringBuilder sb = new StringBuilder();
        for (int i = 1; i <= N; i++) {
        	sb.append(dancers[i] + " ");
        }
        System.out.println(sb.toString());
    }

    public static LinkedList<Integer> make3() {
    	LinkedList<Integer> lst = new LinkedList<Integer>();
    	lst.add(1);
    	lst.add(2);
    	lst.add(3);
    	return lst;
    }

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

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

        int[] nextIntArray(int n) {
        	int[] arr = new int[n];
        	for (int i = 0; i < n; i++) {
        		arr[i] = nextInt();
        	}
        	return arr;
        }

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

        double nextDouble() {
            return Double.parseDouble(next());
        }

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

        String nextLine() {
            String str = "";
            try { str = br.readLine(); }
            catch (IOException e) { e.printStackTrace(); }
            return str;
        }
    }
}


import java.io.BufferedInputStream;
import java.util.Scanner;

public class FlagDay {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedInputStream(System.in));

		int n = in.nextInt();
		int m = in.nextInt();
		int[] dancer = new int[n + 1];
		for(int i = 0; i < m; i++) {
			int a = in.nextInt();
			int b = in.nextInt();
			int c = in.nextInt();
			if(dancer[a] != 0) {
				if(dancer[a] == 1) {
					dancer[b] = 2;
					dancer[c] = 3;
				} else if(dancer[a] == 2) {
					dancer[b] = 1;
					dancer[c] = 3;
				} else {
					dancer[b] = 1;
					dancer[c] = 2;
				}
			} else if(dancer[b] != 0) {
				if(dancer[b] == 1) {
					dancer[a] = 2;
					dancer[c] = 3;
				} else if(dancer[b] == 2) {
					dancer[a] = 1;
					dancer[c] = 3;
				} else {
					dancer[a] = 1;
					dancer[c] = 2;
				}
			} else if(dancer[c] != 0) {
				if(dancer[c] == 1) {
					dancer[a] = 2;
					dancer[b] = 3;
				} else if(dancer[c] == 2) {
					dancer[a] = 1;
					dancer[b] = 3;
				} else {
					dancer[a] = 1;
					dancer[b] = 2;
				}
			} else {
				dancer[a] = 1;
				dancer[b] = 2;
				dancer[c] = 3;
			}
		}

		in.close();

		System.out.print(dancer[1]);
		for(int i = 2; i < n + 1; i++) {
			System.out.print(" " + dancer[i]);
		}
	}

}


import java.io.BufferedInputStream;
import java.util.Scanner;

public class FlagDay {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedInputStream(System.in));

		int n = in.nextInt();
		int m = in.nextInt();
		int[] dancer = new int[n + 1];
		for(int i = 0; i < m; i++) {
			int a = in.nextInt();
			int b = in.nextInt();
			int c = in.nextInt();
			if(dancer[a] != 0) {
				if(dancer[a] == 1) {
					dancer[b] = 2;
					dancer[c] = 3;
				} else if(dancer[a] == 2) {
					dancer[b] = 1;
					dancer[c] = 3;
				} else {
					dancer[b] = 1;
					dancer[b] = 2;
				}
			} else if(dancer[b] != 0) {
				if(dancer[b] == 1) {
					dancer[a] = 2;
					dancer[c] = 3;
				} else if(dancer[b] == 2) {
					dancer[a] = 1;
					dancer[c] = 3;
				} else {
					dancer[a] = 1;
					dancer[c] = 2;
				}
			} else if(dancer[c] != 0) {
				if(dancer[c] == 1) {
					dancer[a] = 2;
					dancer[b] = 3;
				} else if(dancer[c] == 2) {
					dancer[a] = 1;
					dancer[b] = 3;
				} else {
					dancer[a] = 1;
					dancer[b] = 2;
				}
			} else {
				dancer[a] = 1;
				dancer[b] = 2;
				dancer[c] = 3;
			}
		}

		in.close();

		System.out.print(dancer[1]);
		for(int i = 2; i < n + 1; i++) {
			System.out.print(" " + dancer[i]);
		}
	}

}


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

public class B {
  public static void main(String[] args){
    FastScanner sc = new FastScanner();
    int n = sc.nextInt();
    int m = sc.nextInt();
    int[][] d = new int[m][3];
    for(int i = 0; i < m; i++) {
      d[i][0] = sc.nextInt();
      d[i][1] = sc.nextInt();
      d[i][2] = sc.nextInt();
    }
    int[] c = new int[n];

    for(int i = 0; i < m; i++) {
      HashSet<Integer> colors = new HashSet<Integer>(Arrays.asList(1, 2, 3));
      for(int j = 0; j < 3; j++) {
        int dancer = d[i][j] - 1;
        if(c[dancer] != 0) {
          colors.remove(c[dancer]);
        }
      }

      for(int j = 0; j < 3; j++) {
        int dancer = d[i][j] - 1;
        if(c[dancer] == 0) {
          int nextColor = colors.iterator().next();
          colors.remove(nextColor);
          c[dancer] = nextColor;
        }
      }
    }

    for(int color : c) {
      System.out.println(color + " ");
    }
  }

  public static class FastScanner {
    BufferedReader br;
    StringTokenizer st;

    public FastScanner(String s) {
      try {
        br = new BufferedReader(new FileReader(s));
      } catch (FileNotFoundException e) {
        e.printStackTrace();
      }
    }

    public FastScanner() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }

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

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

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

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


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class B1_FlagDay {
    public static void main(String... args) throws IOException {
        MyScanner sc = new MyScanner();

        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] c = new int[n];
        for (int i=0; i<n; i++){
            c[i] = -1;
        }

        for (int i=0; i<m; i++){
            int[] d = new int[3];
            int usedColour = 1;
            ArrayList<Integer> updateList = new ArrayList<>();
            for (int j=0;j<3;j++){
                d[j] = sc.nextInt()-1;
                if (c[d[j]] == -1){
                    updateList.add(d[j]);
                } else {
                    usedColour = c[d[j]];
                }
            }

            for (Integer ind : updateList){
                c[ind] = (usedColour++ % 3) +1;
            }
        }

        for (int i=0; i<n; i++){
            System.out.print(c[i]+ " ");
        }
    }

    static class MyScanner {

        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() throws IOException {
            if (st == null || !st.hasMoreTokens()) {
                String line = br.readLine();
                st = new StringTokenizer(line);
            }
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            String next = next();
            return Integer.parseInt(next);
        }
    }
}


import java.util.*;
public class temp
{ //static {System.out.println("hello");}

  public static void main(String args[])
 { Scanner scn=new Scanner(System.in);
     int n=scn.nextInt();
     int m=scn.nextInt(); int a[][]=new int[m+1][4];
     for(int i=1;i<=m;i++)
     {  for(int j=1;j<=3;j++)
         {
             a[i][j]=scn.nextInt();

        }
     }
           int color[]=new int[n+1];
       for(int i=1;i<=m;i++)
       {int min,max;
          if (color[a[i][1]]==0)
           {  min=color[a[i][2]]<color[a[i][3]] ? color[a[i][2]] : color[a[i][3]];
               max=color[a[i][2]]>color[a[i][3]] ? color[a[i][2]] : color[a[i][3]];
               if (max-min>1) color[a[i][1]]=min+1;
               else if (max+1<=3) color[a[i][1]]=max+1;
               else if (min-1>=1) color[a[i][1]]=min-1;
           }

           if (color[a[i][2]]==0)
           {  min=color[a[i][1]]<color[a[i][3]] ? color[a[i][1]] : color[a[i][3]];
               max=color[a[i][1]]>color[a[i][3]] ? color[a[i][1]] : color[a[i][3]];
               if (max-min>1) color[a[i][2]]=min+1;
               else if (max+1<=3) color[a[i][2]]=max+1;
               else if (min-1>=1) color[a[i][2]]=min-1;
           }

            if (color[a[i][3]]==0)
           {  min=color[a[i][2]]<color[a[i][1]] ? color[a[i][2]] : color[a[i][1]];
               max=color[a[i][2]]>color[a[i][1]] ? color[a[i][2]] : color[a[i][1]];
               if (max-min>1) color[a[i][3]]=min+1;
               else if (max+1<=3) color[a[i][3]]=max+1;
               else if (min-1>=1) color[a[i][3]]=min-1;
           }

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

    }
}


import java.util.Arrays;
import java.util.Scanner;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Yedige
 */
public class Flag {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(), m = in.nextInt(),nn[][] = new int[m][3];int ind[]=new int[n];
        for (int i = 0; i < m; i++) {
            boolean a[] = new boolean[3];a[0]=true;a[1]=true;a[2]=true;
            int p[]=new int [3];p[0]=-1;p[1]=-1;p[2]=-1;
            for (int j = 0; j < 3; j++) {
                nn[i][j] = in.nextInt();
                if(ind[nn[i][j]-1]==0){p[j]=nn[i][j]-1;}else{a[ind[nn[i][j]-1]-1]=false;}
            }
            //System.out.println("P "+Arrays.toString(p));
            for (int k = 0; k < 3; k++) {
                if(a[k]){
                    for(int l = 0; l < 3; l++){if(p[l]!=-1){
                    ind[p[l]]=k+1; p[l]=-1;break;}
            }
                  //  System.out.println("P "+Arrays.toString(p));

        }}}
        for (int k = 0; k < ind.length; k++) {
        System.out.print(ind[k]+" ");

    }

}
}


import java.util.Arrays;
import java.util.Scanner;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Yedige
 */
public class Flag {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(), m = in.nextInt(),nn[][] = new int[m][3];int ind[]=new int[n];
        for (int i = 0; i < m; i++) {
            boolean a[] = new boolean[3];a[0]=true;a[1]=true;a[2]=true;
            int p[]=new int [3];p[0]=-1;p[1]=-1;p[2]=-1;
            for (int j = 0; j < 3; j++) {
                nn[i][j] = in.nextInt();
                if(ind[nn[i][j]-1]==0){p[j]=nn[i][j]-1;}else{a[ind[nn[i][j]-1]-1]=false;}
            }
            //System.out.println("P "+Arrays.toString(p));
            for (int k = 0; k < 3; k++) {
                if(a[k]){
                    for(int l = 0; l < 3; l++){if(p[l]!=-1){
                    ind[p[l]]=k+1; p[l]=-1;break;}
            }
                  //  System.out.println("P "+Arrays.toString(p));

        }}}
        for (int k = 0; k < ind.length; k++) {
        System.out.print(ind[k]+" ");

    }

}


import java.util.*;
import java.io.*;
import java.awt.Point;
import java.math.BigDecimal;
import java.math.BigInteger;

import static java.lang.Math.*;

// Solution is at the bottom of code

public class B implements Runnable{

	final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

	BufferedReader in;
	OutputWriter out;
	StringTokenizer tok = new StringTokenizer("");

	public static void main(String[] args){
		new Thread(null, new B(), "", 128 * (1L << 20)).start();
	}

	/////////////////////////////////////////////////////////////////////

	void init() throws FileNotFoundException{
		Locale.setDefault(Locale.US);

		if (ONLINE_JUDGE){
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new OutputWriter(System.out);
		}else{
			in = new BufferedReader(new FileReader("input.txt"));
			out = new OutputWriter("output.txt");
		}
	}

	////////////////////////////////////////////////////////////////

	long timeBegin, timeEnd;

	void time(){
		timeEnd = System.currentTimeMillis();
		System.err.println("Time = " + (timeEnd - timeBegin));
	}

	void debug(Object... objects){
		if (ONLINE_JUDGE){
			for (Object o: objects){
				System.err.println(o.toString());
			}
		}
	}

	/////////////////////////////////////////////////////////////////////

	public void run(){
		try{
			timeBegin = System.currentTimeMillis();
			Locale.setDefault(Locale.US);

			init();
			solve();

			out.close();
			time();
		}catch (Exception e){
			e.printStackTrace(System.err);
			System.exit(-1);
		}
	}

	/////////////////////////////////////////////////////////////////////

	String delim = " ";

	String readString() throws IOException{
		while(!tok.hasMoreTokens()){
			try{
				tok = new StringTokenizer(in.readLine());
			}catch (Exception e){
				return null;
			}
		}

		return tok.nextToken(delim);
	}

	String readLine() throws IOException{
		return in.readLine();
	}

	/////////////////////////////////////////////////////////////////

	final char NOT_A_SYMBOL = '\0';

	char readChar() throws IOException{
		int intValue = in.read();

		if (intValue == -1){
			return NOT_A_SYMBOL;
		}

		return (char) intValue;
	}

	char[] readCharArray() throws IOException{
		return readLine().toCharArray();
	}

	/////////////////////////////////////////////////////////////////

	int readInt() throws IOException{
		return Integer.parseInt(readString());
	}

	int[] readIntArray(int size) throws IOException{
		int[] array = new int[size];

		for (int index = 0; index < size; ++index){
			array[index] = readInt();
		}

		return array;
	}

	///////////////////////////////////////////////////////////////////

	long readLong() throws IOException{
		return Long.parseLong(readString());
	}

	long[] readLongArray(int size) throws IOException{
		long[] array = new long[size];

		for (int index = 0; index < size; ++index){
			array[index] = readLong();
		}

		return array;
	}

	////////////////////////////////////////////////////////////////////

	double readDouble() throws IOException{
		return Double.parseDouble(readString());
	}

	double[] readDoubleArray(int size) throws IOException{
		double[] array = new double[size];

		for (int index = 0; index < size; ++index){
			array[index] = readDouble();
		}

		return array;
	}

	////////////////////////////////////////////////////////////////////

	BigInteger readBigInteger() throws IOException {
		return new BigInteger(readString());
	}

	BigDecimal readBigDecimal() throws IOException {
		return new BigDecimal(readString());
	}

	/////////////////////////////////////////////////////////////////////

	Point readPoint() throws IOException{
		int x = readInt();
		int y = readInt();
		return new Point(x, y);
	}

	Point[] readPointArray(int size) throws IOException{
		Point[] array = new Point[size];

		for (int index = 0; index < size; ++index){
			array[index] = readPoint();
		}

		return array;
	}

	/////////////////////////////////////////////////////////////////////

	List<Integer>[] readGraph(int vertexNumber, int edgeNumber)
	throws IOException{
		@SuppressWarnings("unchecked")
		List<Integer>[] graph = new List[vertexNumber];

		for (int index = 0; index < vertexNumber; ++index){
			graph[index] = new ArrayList<Integer>();
		}

		while (edgeNumber-- > 0){
			int from = readInt() - 1;
			int to = readInt() - 1;

			graph[from].add(to);
			graph[to].add(from);
		}

		return graph;
	}

	/////////////////////////////////////////////////////////////////////

	static class IntIndexPair {

		static Comparator<IntIndexPair> increaseComparator = new Comparator<B.IntIndexPair>() {

			@Override
			public int compare(IntIndexPair indexPair1, IntIndexPair indexPair2) {
				int value1 = indexPair1.value;
				int value2 = indexPair2.value;

				if (value1 != value2) return value1 - value2;

				int index1 = indexPair1.index;
				int index2 = indexPair2.index;

				return index1 - index2;
			}
		};

		static Comparator<IntIndexPair> decreaseComparator = new Comparator<B.IntIndexPair>() {

			@Override
			public int compare(IntIndexPair indexPair1, IntIndexPair indexPair2) {
				int value1 = indexPair1.value;
				int value2 = indexPair2.value;

				if (value1 != value2) return -(value1 - value2);

				int index1 = indexPair1.index;
				int index2 = indexPair2.index;

				return index1 - index2;
			}
		};

		int value, index;

		public IntIndexPair(int value, int index) {
			super();
			this.value = value;
			this.index = index;
		}
	}

	IntIndexPair[] readIntIndexArray(int size) throws IOException {
		IntIndexPair[] array = new IntIndexPair[size];

		for (int index = 0; index < size; ++index) {
			array[index] = new IntIndexPair(readInt(), index);
		}

		return array;
	}

	/////////////////////////////////////////////////////////////////////

	static class OutputWriter extends PrintWriter{

		final int DEFAULT_PRECISION = 12;

		int precision;
		String format, formatWithSpace;

		{
			precision = DEFAULT_PRECISION;

			format = createFormat(precision);
			formatWithSpace = format + " ";
		}

		public OutputWriter(OutputStream out) {
			super(out);
		}

		public OutputWriter(String fileName) throws FileNotFoundException {
			super(fileName);
		}

		public int getPrecision() {
			return precision;
		}

		public void setPrecision(int precision) {
			precision = max(0, precision);
			this.precision = precision;

			format = createFormat(precision);
			formatWithSpace = format + " ";
		}

		private String createFormat(int precision){
			return "%." + precision + "f";
		}

		@Override
		public void print(double d){
			printf(format, d);
		}

		public void printWithSpace(double d){
			printf(formatWithSpace, d);
		}

		public void printAll(double...d){
			for (int i = 0; i < d.length - 1; ++i){
				printWithSpace(d[i]);
			}

			print(d[d.length - 1]);
		}

		@Override
		public void println(double d){
			printlnAll(d);
		}

		public void printlnAll(double... d){
			printAll(d);
			println();
		}
	}

	/////////////////////////////////////////////////////////////////////

	int[][] steps = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
	int[][] steps8 = {
			{-1, 0}, {1, 0}, {0, -1}, {0, 1},
			{-1, -1}, {1, 1}, {1, -1}, {-1, 1}
	};

	boolean check(int index, int lim){
		return (0 <= index && index < lim);
	}

	/////////////////////////////////////////////////////////////////////

	boolean checkBit(int mask, int bitNumber){
		return (mask & (1 << bitNumber)) != 0;
	}

	/////////////////////////////////////////////////////////////////////

	void solve() throws IOException {
		int n = readInt();
		int m = readInt();

		int[][] dances = new int[m][3];
		for (int i = 0; i < m; ++i) {
			dances[i] = readIntArray(3);
		}

		int[] colors = getColors(n, m, dances);
		for (int color: colors) {
			out.print(color + " ");
		}
	}

	int WHITE = 0, RED = 1, BLUE = 2;

	private int[] getColors(int n, int m, int[][] dances) {
		for (int i = 0; i < m; ++i) {
			for (int j = 0; j < 3; ++j) {
				dances[i][j]--;
			}
		}

		int[] colors = new int[n];
		Arrays.fill(colors, (1 << 3) - 1);

		@SuppressWarnings("unchecked")
		List<Integer>[] graph = new List[n];
		for (int i = 0; i < n; ++i) {
			graph[i] = new ArrayList<Integer>();
		}

		for (int i = 0; i < m; ++i) {
			for (int dancer: dances[i]) {
				graph[dancer].add(i);
			}
		}

		@SuppressWarnings("unchecked")
		Queue<Integer>[] colorCounts = new Queue[3];
		for (int i = 0; i < 3; ++i) {
			colorCounts[i] = new ArrayDeque<Integer>();
		}

		Queue<Integer> three = colorCounts[2];
		Queue<Integer> two = colorCounts[1];
		Queue<Integer> one = colorCounts[0];

		for (int i = 0; i < n; ++i) {
			three.add(i);
		}

		boolean[] used = new boolean[n];

		while (three.size() > 0) {
			int fromThree = three.poll();
			if (used[fromThree]) continue;

			colors[fromThree] = removeColor(colors[fromThree]);

			two.add(fromThree);
			while (two.size() > 0) {
				int fromTwo = two.poll();
				if (used[fromTwo]) continue;

				colors[fromTwo] = removeColor(colors[fromTwo]);

				one.add(fromTwo);
				while (one.size() > 0) {
					int fromOne = one.poll();
					if (used[fromOne]) continue;

					used[fromOne] = true;

					int curColor = colors[fromOne];
					for (int danceIndex: graph[fromOne]) {
						int[] dance = dances[danceIndex];

						for (int dancer: dance) {
							if (used[dancer]) continue;

							colors[dancer] ^= curColor;

							int colorCount = Integer.bitCount(colors[dancer]);
							colorCounts[colorCount - 1].add(dancer);
						}
					}
				}
			}
		}

		for (int i = 0; i < n; ++i) {
			for (int color = 0; color < 3; ++color) {
				if (checkBit(colors[i], color)) {
					colors[i] = color + 1;
					break;
				}
			}
		}

		return colors;
	}

	int removeColor(int colors) {
		for (int color = 2; color >= 0; --color) {
			if (checkBit(colors, color)) {
				colors ^= (1 << color);
				break;
			}
		}

		return colors;
	}
}


import java.util.Arrays;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * User: samir
 * Date: 10/19/13
 * Time: 1:58 AM
 * To change this template use File | Settings | File Templates.
 */
public class B {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] colors = new int[n + 1];
        Arrays.fill(colors, -1);

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

            for(int color = 0; color <= 2; ++color) {
                boolean avalid = false;
                boolean bvalid = false;
                boolean cvalid = false;

                if(colors[a] == -1 || colors[a] == color) avalid = true;
                if(colors[b] == -1 || colors[b] == (color + 1) % 3) bvalid = true;
                if(colors[c] == -1 || colors[c] == (color + 2) % 3) cvalid = true;
                if(avalid && bvalid && cvalid) {
                    colors[a] = color;
                    colors[b] = (color + 1) % 3;
                    colors[c] = (color + 2) % 3;
                }
            }
        }

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


import java.util.Arrays;
import java.util.Scanner;

public class Main2 {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] num = new int[n];
		for(int i = 0 ; i < m ; i++){
			int fst = sc.nextInt();
			int sst = sc.nextInt();
			int tst = sc.nextInt();
			boolean used[] = new boolean[4];
			used[num[fst-1]] = true;
			used[num[sst-1]] = true;
			used[num[tst-1]] = true;
			for(int j = 1 ; j < 4 ; j++){
				if(!used[j]){
					if(num[fst-1] == 0){
						num[fst-1] = j;
					}else if(num[sst-1] == 0){
						num[sst-1] = j;
					}else if(num[tst-1] == 0){
						num[tst-1] = j;
					}
				}
			}
		}
		for(int i = 0 ; i < n ; i++){
			if(i != n-1){
				System.out.print(num[i]+" ");
			}else{
				System.out.println(num[i]);
			}
		}
	}
}


import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class CFC207B {

    public static void main(String[] args) throws FileNotFoundException {
        //Scanner in = new Scanner(new File("input.txt"));
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int a[] = new int[n+1];
        for (int i = 0; i < m; i++) {
            int x1 = in.nextInt();
            int x2 = in.nextInt();
            int x3 = in.nextInt();
            if (a[x2] > 0)
            {int t = x1; x1 = x2; x2 = t;}
            else if (a[x3] > 0)
            {int t = x1; x1 = x3; x3 = t;}
            if (a[x1] == 0)
                a[x1]++;
            a[x1]--;
            a[x2] = (a[x1] + 1) % 3 + 1;
            a[x3] = (a[x1] + 2) % 3 + 1;
            a[x1]++;
        }
        for (int i = 1; i <= n; i++)
            System.out.print(a[i] + " ");

    }

}


import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class CFC207B {

    public static void main(String[] args) throws FileNotFoundException {
        //Scanner in = new Scanner(new File("input.txt"));
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int a[] = new int[n+1];
        for (int i = 0; i < m; i++) {
            int x1 = in.nextInt();
            int x2 = in.nextInt();
            int x3 = in.nextInt();
            if (a[x2] == 1)
            {int t = x1; x1 = x2; x2 = t;}
            else if (a[x3] == 1)
            {int t = x1; x1 = x3; x3 = t;}
            if (a[x1] == 0)
                a[x1]++;
            a[x1]--;
            a[x2] = (a[x1] + 1) % 3 + 1;
            a[x3] = (a[x1] + 2) % 3 + 1;
            a[x1]++;
        }
        for (int i = 1; i <= n; i++)
            System.out.print(a[i] + " ");

    }

}


import java.util.Arrays;
import java.util.Scanner;

public class Main {
  public static void main(String[] args)
  {
    Scanner in = new Scanner(System.in);

    int n = in.nextInt(), m = in.nextInt();

    int[] dancers = new int[n];
    Arrays.fill(dancers, 0);

    int i;
    int c1, c2;

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

      if (dancers[a] + dancers[b] + dancers[c] == 0) {
        dancers[a] = 1;
        dancers[b] = 2;
        dancers[c] = 3;
      }
      else {
        if (dancers[a] != 0) {
          c1 = col(dancers[a]);
          c2 = col(dancers[a], c1);
          dancers[b] = c1;
          dancers[c] = c2;
        } else
        if (dancers[b] != 0) {
          c1 = col(dancers[b]);
          c2 = col(dancers[b], c1);
          dancers[a] = c1;
          dancers[c] = c2;
        } else
        if (dancers[c] != 0) {
          c1 = col(dancers[c]);
          c2 = col(dancers[c], c1);
          dancers[a] = c1;
          dancers[b] = c2;
        }
      }
    }
    for (i = 0; i < n; i++) {
      System.out.format("%d ", dancers[i]);
    }
    System.out.println();
  }

  private static int col(int dancer, int c1) {
    return (1+2+3)-dancer-c1;
  }

  private static int col(int dancer) {
    if (dancer == 1)
      return 2;
    else if (dancer == 2)
      return 3;
    return 1;
  }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.StringTokenizer;

/**
 * @author artyom
 */
public class FlagDaySimplied implements Runnable {
	private BufferedReader in;
	private PrintStream out;
	private StringTokenizer tok;

	private static final int[][] NON_STRICT_COLOURS;

	static {
		NON_STRICT_COLOURS = new int[4][4];
		NON_STRICT_COLOURS[1] = new int[]{2, 3};
		NON_STRICT_COLOURS[2] = new int[]{1, 3};
		NON_STRICT_COLOURS[3] = new int[]{1, 2};
	}

	private void solve() throws IOException {
		int n = nextInt();
		int[] a = new int[n + 1];
		for (int i = 0, m = nextInt(); i < m; i++) {
			int x = nextInt(), y = nextInt(), z = nextInt();
			int ax = a[x], ay = a[y], az = a[z];
			if (ax > 0) {
				a[y] = NON_STRICT_COLOURS[ax][0];
				a[z] = NON_STRICT_COLOURS[ax][1];
			} else if (ay > 0) {
				a[x] = NON_STRICT_COLOURS[ay][0];
				a[z] = NON_STRICT_COLOURS[ay][1];
			} else if (az > 0) {
				a[x] = NON_STRICT_COLOURS[az][0];
				a[y] = NON_STRICT_COLOURS[az][1];
			} else {
				a[x] = 1;
				a[y] = 2;
				a[z] = 3;
			}
		}
		out.println(join(a, " "));
	}

	//--------------------------------------------------------------
	public static void main(String[] args) {
		new FlagDaySimplied().run();
	}

	@Override
	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = System.out;
			tok = null;
			solve();
			in.close();
		} catch (IOException e) {
			System.exit(0);
		}
	}

	private static String join(int[] entries, CharSequence separator) {
		StringBuilder sb = new StringBuilder();
		for (int i = 1, n = entries.length - 1; i <= n; i++) {
			sb.append(entries[i]);
			if (i < n) {
				sb.append(separator);
			}
		}
		return sb.toString();
	}

	private String nextToken() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

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


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.StringTokenizer;

/**
 * @author artyom
 */
public class FlagDay implements Runnable {
	private BufferedReader in;
	private PrintStream out;
	private StringTokenizer tok;

	private static final int[][] STRICT_COLOURS;
	private static final int[][] NON_STRICT_COLOURS;

	static {
		STRICT_COLOURS = new int[4][4];
		STRICT_COLOURS[1][2] = STRICT_COLOURS[2][1] = 3;
		STRICT_COLOURS[1][3] = STRICT_COLOURS[3][1] = 2;
		STRICT_COLOURS[2][3] = STRICT_COLOURS[3][2] = 1;
	}

	static {
		NON_STRICT_COLOURS = new int[4][4];
		NON_STRICT_COLOURS[1] = new int[]{2, 3};
		NON_STRICT_COLOURS[2] = new int[]{1, 3};
		NON_STRICT_COLOURS[3] = new int[]{1, 2};
	}

	private void solve() throws IOException {
		int n = nextInt();
		int[] a = new int[n + 1];
		for (int i = 0, m = nextInt(); i < m; i++) {
			int x = nextInt(), y = nextInt(), z = nextInt();
			int ax = a[x], ay = a[y], az = a[z];
			if (ax > 0) {
				if (ay > 0) {
					a[z] = STRICT_COLOURS[ax][ay];
				} else if (az > 0) {
					a[y] = STRICT_COLOURS[ax][az];
				} else {
					a[y] = NON_STRICT_COLOURS[ax][0];
					a[z] = NON_STRICT_COLOURS[ax][1];
				}
			} else if (ay > 0) {
				if (az > 0) {
					a[x] = STRICT_COLOURS[ay][az];
				} else {
					a[x] = NON_STRICT_COLOURS[ay][0];
					a[z] = NON_STRICT_COLOURS[ay][1];
				}
			} else if (az > 0) {
				a[x] = NON_STRICT_COLOURS[az][0];
				a[y] = NON_STRICT_COLOURS[az][1];
			} else {
				a[x] = 1;
				a[y] = 2;
				a[z] = 3;
			}
		}
		out.println(join(a, " "));
	}

	//--------------------------------------------------------------
	public static void main(String[] args) {
		new FlagDay().run();
	}

	@Override
	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = System.out;
			tok = null;
			solve();
			in.close();
		} catch (IOException e) {
			System.exit(0);
		}
	}

	private int[] readArray(int n) throws IOException {
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nextInt();
		}
		return arr;
	}

	private static String join(int[] entries, CharSequence separator) {
		StringBuilder sb = new StringBuilder();
		for (int i = 1, n = entries.length - 1; i <= n; i ++) {
			sb.append(entries[i]);
			if (i < n) {
				sb.append(separator);
			}
		}
		return sb.toString();
	}

	private String nextToken() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	private short nextShort() throws IOException {
		return Short.parseShort(nextToken());
	}

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

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


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.StringTokenizer;

/**
 * @author artyom
 */
public class FlagDay implements Runnable {
	private BufferedReader in;
	private PrintStream out;
	private StringTokenizer tok;

	private static final int[][] STRICT_COLOURS;
	private static final int[][] NON_STRICT_COLOURS;

	static {
		STRICT_COLOURS = new int[4][4];
		STRICT_COLOURS[1][2] = STRICT_COLOURS[2][1] = 3;
		STRICT_COLOURS[1][3] = STRICT_COLOURS[1][3] = 2;
		STRICT_COLOURS[2][3] = STRICT_COLOURS[3][2] = 1;
	}

	static {
		NON_STRICT_COLOURS = new int[4][4];
		NON_STRICT_COLOURS[1] = new int[]{2, 3};
		NON_STRICT_COLOURS[2] = new int[]{1, 3};
		NON_STRICT_COLOURS[3] = new int[]{1, 2};
	}

	private void solve() throws IOException {
		int n = nextInt();
		int[] a = new int[n + 1];
		for (int i = 0, m = nextInt(); i < m; i++) {
			int x = nextInt(), y = nextInt(), z = nextInt();
			int ax = a[x], ay = a[y], az = a[z];
			if (ax > 0) {
				if (ay > 0) {
					a[z] = STRICT_COLOURS[ax][ay];
				} else if (az > 0) {
					a[y] = STRICT_COLOURS[ax][az];
				} else {
					a[y] = NON_STRICT_COLOURS[ax][0];
					a[z] = NON_STRICT_COLOURS[ax][1];
				}
			} else if (ay > 0) {
				if (az > 0) {
					a[x] = STRICT_COLOURS[ay][az];
				} else {
					a[x] = NON_STRICT_COLOURS[ay][0];
					a[z] = NON_STRICT_COLOURS[ay][1];
				}
			} else if (az == 0) {
				a[x] = 1;
				a[y] = 2;
				a[z] = 3;
			}
		}
		out.println(join(a, " "));
	}

	//--------------------------------------------------------------
	public static void main(String[] args) {
		new FlagDay().run();
	}

	@Override
	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = System.out;
			tok = null;
			solve();
			in.close();
		} catch (IOException e) {
			System.exit(0);
		}
	}

	private int[] readArray(int n) throws IOException {
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nextInt();
		}
		return arr;
	}

	private static String join(int[] entries, CharSequence separator) {
		StringBuilder sb = new StringBuilder();
		for (int i = 1, n = entries.length - 1; i <= n; i ++) {
			sb.append(entries[i]);
			if (i < n) {
				sb.append(separator);
			}
		}
		return sb.toString();
	}

	private String nextToken() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	private short nextShort() throws IOException {
		return Short.parseShort(nextToken());
	}

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

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


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

public class Main {
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    static void solve() throws Exception {
        int n = nextInt();
        int m = nextInt();
        int[] color = new int[n+1];
        for (int i = 1; i <= m; i++) {
            int a = nextInt();
            int b = nextInt();
            int c = nextInt();
            if (color[a] == 0 && color[b] == 0 && color[c] == 0) {
                color[a] = 1;
                color[b] = 2;
                color[c] = 3;
            } else if (color[a] != 0) {
                if (color[a] == 1) {
                    color[b] = 2;
                    color[c] = 3;
                } else if (color[a] == 2) {
                    color[b] = 1;
                    color[c] = 3;
                } else {
                    color[b] = 1;
                    color[c] = 2;
                }
            } else if (color[b] != 0) {
                if (color[b] == 1) {
                    color[a] = 2;
                    color[c] = 3;
                } else if (color[b] == 2) {
                    color[a] = 1;
                    color[c] = 3;
                } else {
                    color[a] = 1;
                    color[c] = 2;
                }
            } else {
                if (color[c] == 1) {
                    color[a] = 2;
                    color[b] = 3;
                } else if (color[c] == 2) {
                    color[a] = 1;
                    color[b] = 3;
                } else {
                    color[a] = 1;
                    color[b] = 2;
                }
            }
        }
        for (int i = 1; i <= n; i++) {
            out.print(color[i] + " ");
        }
        out.println();
    }

    static int sqr(int x) {
        return x*x;
    }

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

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

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

    static BigInteger nextBigInteger() throws IOException {
        return new BigInteger(next());
    }

    static String next() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

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

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

    public static void main(String args[]) {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(new OutputStreamWriter(System.out));
            //in = new BufferedReader(new FileReader("input.in"));
            //out = new PrintWriter(new FileWriter("output.out"));
            solve();
            in.close();
            out.close();
        } catch (Throwable e) {
            e.printStackTrace();
            java.lang.System.exit(1);
        }
    }
}


//package main;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {

        Solve solve = new Solve(new ConsoleIOFast());
        solve.getSolve();
    }
}

interface TypeIO {

    void solve() throws IOException;
}

class FileIO implements TypeIO {

    @Override
    public void solve() throws IOException {
        Scanner sc = new Scanner(new File("input.txt"));
        PrintWriter pw = new PrintWriter(new File("output.txt"));
        sc.close();
        pw.close();
    }
}

class ConsoleIOFast implements TypeIO {

    BufferedReader in;
    StringTokenizer tok;
    PrintWriter out;

    String readToken() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readToken());
    }

    String readString() throws IOException {
        return readToken();
    }

    @Override
    public void solve() throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        int n = readInt();
        int m = readInt();
        Graph graph = new Graph(n);
        for(int i = 0; i < m; i++){
            int tmp[] = new int[3];
            for(int j = 0; j < 3; j++){
                tmp[j] = readInt() - 1;
            }
            graph.addEdgeNotOriented(tmp[0], tmp[1]);
            graph.addEdgeNotOriented(tmp[0], tmp[2]);
            graph.addEdgeNotOriented(tmp[1], tmp[2]);
        }
        for(int i = 0; i < graph.getUsed().length; i++){
            if(graph.getUsed()[i] == 0){
                graph.dfs(i);
            }
        }
        for(int value : graph.getColor()){
            System.out.print(value + " ");
        }
        out.close();
        in.close();
    }
}

class ConsoleIO implements TypeIO {

    @Override
    public void solve() throws IOException {
        Scanner sc = new Scanner(System.in);

        sc.close();
    }
}

class Solve {

    private TypeIO typeIO;

    public Solve(TypeIO typeIO) {
        this.typeIO = typeIO;
    }

    void getSolve() throws IOException {
        typeIO.solve();
    }
}
class Graph {

    private int used[];
    private LinkedList<Integer> nodes[];
    private int color[];

    public Graph(int n) {
        used = new int[n];
        color = new int[n];
        nodes = new LinkedList[n];
        for(int i = 0; i < n; i++){
            nodes[i] = new LinkedList<>();
        }
    }

    void dfs(int start) {
        used[start] = 1;
        int a[] = new int [4];
        for(int value : nodes[start]){
            if(color[value] > 0){
                a[color[value]] = 1;
            }
        }
        for(int i = 1; i < 4; i++){
            if(a[i] == 0){
                color[start] = i;
                break;
            }
        }
        Iterator it = nodes[start].listIterator();
        while (it.hasNext()) {
            int curr = (Integer) it.next();
            if(used[curr] == 0){
                dfs(curr);
            }
        }
    }

    int [] getUsed(){
        return used;
    }

    int [] getColor(){
        return color;
    }

    public void addEdgeNotOriented(int first, int second) {
        nodes[first].add(second);
        nodes[second].add(first);
    }
}


import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Stack;

public class B {

	static ArrayList<LinkedList<Integer> > g;
	static boolean[] vis;
	static int colors[];
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		g = new ArrayList();
		int n  = in.nextInt();
		int m = in.nextInt();
		for(int i = 0; i <n; i++){
			g.add(new LinkedList<Integer>());
		}
		for(int i = 0; i < m; i++){
			int a = in.nextInt()-1;
			int b = in.nextInt()-1;
			int c = in.nextInt()-1;
			g.get(a).add(b);
			g.get(b).add(a);

			g.get(a).add(c);
			g.get(c).add(a);

			g.get(b).add(c);
			g.get(c).add(b);

		}
		while(true){
			vis = new boolean[n];
			colors = new int[n];
			for(int i = 0; i < n; i++) colors[i] = -1;
			boolean ok = true;
			for(int i = 0; i < n; i++){
				if(!vis[i]){
					if(!dfs(i, 0)) ok = false;
				}
			}
			if(ok){
			for(int i : colors){
				System.out.print(i + " ");
			}
			System.out.println();
			break;
			}
		}
	}
	public static boolean dfs(int node, int color){
		if(color == 0) color++;
		vis[node] = true;
		colors[node] = color;
		for(int nabo : g.get(node)){
			if(colors[nabo] == color) return false;
			if(!vis[nabo]){
				if(!dfs(nabo, (color+1)%4)) return false;
			}
		}
		return true;
	}

}


import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Stack;

public class B {

	static ArrayList<LinkedList<Integer> > g;
	static boolean[] vis;
	static int colors[];
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		g = new ArrayList();
		int n  = in.nextInt();
		int m = in.nextInt();
		for(int i = 0; i <n; i++){
			g.add(new LinkedList<Integer>());
		}
		for(int i = 0; i < m; i++){
			int a = in.nextInt()-1;
			int b = in.nextInt()-1;
			int c = in.nextInt()-1;
			g.get(a).add(b);
			g.get(b).add(a);

			g.get(a).add(c);
			g.get(c).add(a);

			g.get(b).add(c);
			g.get(c).add(b);

		}
		vis = new boolean[n];
		colors = new int[n];
		dfs(0, 1);
		for(int i : colors){
			System.out.print(i + " ");
		}
		System.out.println();
	}
	public static void dfs(int node, int color){
		vis[node] = true;
		colors[node] = color;
		for(int nabo : g.get(node)){
			if(!vis[nabo]){
				dfs(nabo, color+1);
			}
		}
	}

}


import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;
import java.util.StringTokenizer;

public class Main
{

	private static BufferedReader in;
	private static BufferedWriter out;

	public static void main(String... args) throws IOException
	{
		// streams
		boolean file = false;
		if (file)
			in = new BufferedReader(new FileReader("input.txt"));
		else
			in = new BufferedReader(new InputStreamReader(System.in));
		out = new BufferedWriter(new OutputStreamWriter(System.out));
		StringTokenizer tok;

		// take input
		tok = new StringTokenizer(in.readLine());
		int n = Integer.parseInt(tok.nextToken());
		int m = Integer.parseInt(tok.nextToken());
		int c[] = new int[n+1];
		for (int i = 0; i < m; i++)
		{
			// read the dance
			int dance[] = new int[3];
			tok =new StringTokenizer(in.readLine());
			for (int j = 0; j < 3; j++)
				dance[j] = Integer.parseInt(tok.nextToken());

			HashSet<Integer> available = new HashSet<>();
			for (int j = 1; j <= 3; j++)
				available.add(j);

			// dress the dancer who already performed
			int dressed = -1;
			for (int j = 0; j < 3; j++)
			{
				if (c[dance[j]] != 0)
				{
					dressed = j;
					available.remove(c[dance[j]]);
				}
			}

			// dress the remaining
			ArrayList<Integer> availableList = new ArrayList<>(available);
			int idx = 0;
			for (int j = 0; j < 3; j++)
			{
				if (j != dressed)
				{
					c[dance[j]] = availableList.get(idx);
					idx ++;
				}
			}
		}

		// output
		StringBuilder ans = new StringBuilder();
		for (int i = 1; i <= n; i++)
			ans.append(c[i] + " ");
		System.out.println(ans.toString().trim());
		out.flush();

	}

}


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

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

/**
 * @author Assassin
 */
public class Div2B {

    private BufferedReader reader;
    private PrintWriter out;
    private StringTokenizer tokenizer;
    //private final String filename = "filename";

    private void init(InputStream input, OutputStream output) throws IOException {
        reader = new BufferedReader(new InputStreamReader(input));
        out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(output)));
        //reader = new BufferedReader(new FileReader(filename + ".in"));
        //out = new PrintWriter(new FileWriter(filename + ".out"));
        tokenizer = new StringTokenizer("");
    }

    private String nextLine() throws IOException {
        return reader.readLine();
    }

    private String next() throws IOException {
        while (!tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(nextLine());
        }
        return tokenizer.nextToken();
    }

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

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

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

    private void run() throws IOException {
        init(System.in, System.out);
        //long startTime = System.currentTimeMillis();
        int n = nextInt();
        int m = nextInt();
        int d1, d2, d3, temp1, temp2, temp3;
        int[] a = new int[111111];
        for (int i = 0; i < m; i++) {
            d1 = nextInt();
            d2 = nextInt();
            d3 = nextInt();
            temp1 = a[d1];
            temp2 = a[d2];
            temp3 = a[d3];
            int sum = temp1 + temp2 + temp3;
            if (temp1 == 0) {
                sum++;
                sum %= 3;
                if (sum == 0) {
                    sum = 3;
                }
                temp1 = sum;
            }
            if (temp2 == 0) {
                sum++;
                sum %= 3;
                if (sum == 0) {
                    sum = 3;
                }
                temp2 = sum;
            }
            if (temp3 == 0) {
                sum++;
                sum %= 3;
                if (sum == 0) {
                    sum = 3;
                }
                temp3 = sum;
            }
            a[d1] = temp1;
            a[d2] = temp2;
            a[d3] = temp3;
            //if(al1.contains(temp1))
        }
        for (int i = 1; i < n; i++) {
            out.print(a[i] + " ");
        }
        out.println(a[n]);
        //long runTime = System.currentTimeMillis() - startTime;
        //out.write(runTime + "\n");
        out.close();
        System.exit(0);
    }

    public static void main(String[] args) throws IOException {
        new Div2B().run();
    }
}


import java.util.ArrayList;
import java.util.Scanner;

public class E{

	public static void main(String[] args) {
		new E();
	}

	public E() {
		Scanner sc = new Scanner(System.in);

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

		int[][] array = new int[m][3];

		for (int i = 0; i < m; i++) {
			for (int j = 0; j < 3; j++) {
				array[i][j] = sc.nextInt();
			}
		}

		int[] colors = new int[n];

		colors[array[0][0]-1] = 1;
		colors[array[0][1]-1] = 2;
		colors[array[0][2]-1] = 3;

		for (int i = 0; i < m; i++) {
			int x = array[i][0];
			int y = array[i][1];
			int z = array[i][2];

			int xNew = 0;
			int yNew = 0;
			int zNew = 0;

			int[] poss = new int[3];

			if (colors[x-1] != 0) {
				xNew = colors[x-1];
				poss[xNew-1] = 1;
			}
			if (colors[y-1] != 0) {
				yNew = colors[y-1];
				poss[yNew-1] = 1;
			}
			if (colors[z-1] != 0) {
				zNew = colors[z-1];
				poss[zNew-1] = 1;
			}

			if (xNew == 0) {
				if (poss[0] == 0) {
					xNew = 1;
					poss[0] = 1;
				} else if (poss[1] == 0) {
					xNew = 2;
					poss[1] = 1;
				} else if (poss[2] == 0) {
					xNew = 3;
					poss[2] = 1;
				}
			}

			if (yNew == 0) {
				if (poss[0] == 0) {
					yNew = 1;
					poss[0] = 1;
				} else if (poss[1] == 0) {
					yNew = 2;
					poss[1] = 1;
				} else if (poss[2] == 0) {
					yNew = 3;
					poss[2] = 1;
				}
			}

			if (zNew == 0) {
				if (poss[0] == 0) {
					zNew = 1;
					poss[0] = 1;
				} else if (poss[1] == 0) {
					zNew = 2;
					poss[1] = 1;
				} else if (poss[2] == 0) {
					zNew = 3;
					poss[2] = 1;
				}
			}

			colors[x-1] = xNew;
			colors[y-1] = yNew;
			colors[z-1] = zNew;
		}

		for (int i = 0; i < n; i++) {
			System.out.println(colors[i]);
		}

		sc.close();
	}
}


import java.util.Scanner;

public class B {

	public static void main(String[] args) {
		new B();
	}

	public B() {
		Scanner sc = new Scanner(System.in);

		sc.close();
	}
}


import java.io.InputStreamReader;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;

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

class TaskB {
    int[] color;

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int m = in.nextInt();
        color = new int[n];
        for (int i = 0; i < m; ++i) {
            int x = in.nextInt() - 1;
            int y = in.nextInt() - 1;
            int z = in.nextInt() - 1;
            if (color[x] == 0) color[x] = whatColor(x, y, z);
            if (color[y] == 0) color[y] = whatColor(x, y, z);
            if (color[z] == 0) color[z] = whatColor(x, y, z);
        }

        for (int x : color) out.print(x + " ");
        out.println();
    }

    private int whatColor(int x, int y, int z) {
        boolean color1 = false;
        boolean color2 = false;
        boolean color3 = false;
        if (color[x] == 1 || color[y] == 1 || color[z] == 1) color1 = true;
        if (color[x] == 2 || color[y] == 2 || color[z] == 2) color2 = true;
        if (color[x] == 3 || color[y] == 3 || color[z] == 3) color3 = true;
        if (!color1) return 1;
        if (!color2) return 2;
        if (!color3) return 3;
        return 0;
    }
}

class InputReader {
    BufferedReader in;
    StringTokenizer st;

    public InputReader(InputStream stream) {
        in = new BufferedReader(new InputStreamReader(stream));
        eat("");
    }

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

    public String next() {
        while (!st.hasMoreTokens())
            eat(nextLine());
        return st.nextToken();
    }

    public String nextLine() {
        try {
            return in.readLine();
        } catch (IOException e) {
            throw new InputMismatchException();
        }
    }

    public void eat(String str) {
        if (str == null) throw new InputMismatchException();
        st = new StringTokenizer(str, " \n:.,");
    }
}


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

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

class FlagDay {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
        int n=in.readInt();
        int m=in.readInt();
        int a[]=new int[n];
        Arrays.fill(a,-1);
        for(int i=0;i<m;++i)
        {
            boolean visited[]=new boolean[3];
            int x[]=new int[3];
            for(int j=0;j<3;++j)
                x[j]=in.readInt()-1;
            for(int j=0;j<3;++j)
                if(a[x[j]]>=0)
                    visited[a[x[j]]]=true;
            for(int j=0;j<3;j++)
            {
                if(a[x[j]]<0)
                {
                    for(int k=0;k<3;++k)
                        if(!visited[k]) {
                            a[x[j]] = k;
                            visited[k]=true;
                            break;
                        }
                }
            }
        }
        for(int i=0;i<n;++i)
            out.print((a[i]+1)+" ");
    }
}

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

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

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

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

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

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

class OutputWriter {
    private final PrintWriter writer;

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

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

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

}