In Berland, there is the national holiday coming — the Flag Day. In the honor of this event the president of the country decided to make a big dance party and asked your agency to organize it. He has several conditions:  overall, there must be m dances; exactly three people must take part in each dance; each dance must have one dancer in white clothes, one dancer in red clothes and one dancer in blue clothes (these are the colors of the national flag of Berland). 

The agency has n dancers, and their number can be less than 3m. That is, some dancers will probably have to dance in more than one dance. All of your dancers must dance on the party. However, if some dance has two or more dancers from a previous dance, then the current dance stops being spectacular. Your agency cannot allow that to happen, so each dance has at most one dancer who has danced in some previous dance. 

You considered all the criteria and made the plan for the m dances: each dance had three dancers participating in it. Your task is to determine the clothes color for each of the n dancers so that the President's third condition fulfilled: each dance must have a dancer in white, a dancer in red and a dancer in blue. The dancers cannot change clothes between the dances.


-----Input-----

The first line contains two space-separated integers n (3 ≤ n ≤ 10^5) and m (1 ≤ m ≤ 10^5) — the number of dancers and the number of dances, correspondingly. Then m lines follow, describing the dances in the order of dancing them. The i-th line contains three distinct integers — the numbers of the dancers that take part in the i-th dance. The dancers are numbered from 1 to n. Each dancer takes part in at least one dance.


-----Output-----

Print n space-separated integers: the i-th number must represent the color of the i-th dancer's clothes (1 for white, 2 for red, 3 for blue). If there are multiple valid solutions, print any of them. It is guaranteed that at least one solution exists.


-----Examples-----
Input
7 3
1 2 3
1 4 5
4 6 7

Output
1 2 3 3 2 2 1 

Input
9 3
3 6 9
2 5 8
1 4 7

Output
1 1 1 2 2 2 3 3 3 

Input
5 2
4 1 5
3 1 2

Output
2 3 1 1 3

Source: codeforces | Difficulty: MEDIUM
Tags: Implementation

Constructive algorithms


Solutions:
(n, m) = (int(x) for x in input().split())
available = [1, 2, 3]
colors = [0] * (n + 1)
for i in range(m):
	(a, b, c) = [int(x) for x in input().split()]
	if colors[a] != 0:
		available.remove(colors[a])
	if colors[b] != 0:
		available.remove(colors[b])
	if colors[c] != 0:
		available.remove(colors[c])
	if len(available) > 0:
		if colors[a] == 0:
			colors[a] = available[0]
			available.remove(colors[a])
		if colors[b] == 0:
			colors[b] = available[0]
			available.remove(colors[b])
		if colors[c] == 0:
			colors[c] = available[0]
			available.remove(colors[c])
	available = [1, 2, 3]
for elt in colors[1:]:
	print(elt, end=' ')


(n, m) = map(int, input().split())
arr = [0] * (n + 1)
for i in range(m):
	(a, b, c) = map(int, input().split())
	temp = [arr[a], arr[b], arr[c]]
	if temp == [0, 0, 0]:
		arr[a] = 1
		arr[b] = 2
		arr[c] = 3
	else:
		remain = list(set([1, 2, 3]) - set(temp))
		if arr[a] == 0:
			arr[a] = remain.pop()
		if arr[b] == 0:
			arr[b] = remain.pop()
		if arr[c] == 0:
			arr[c] = remain.pop()
print(*arr[1:])


(n, m) = map(int, input().split())
dancers = {'auther': 'wanglizhi'}
for i in range(m):
	(a, b, c) = map(int, input().split())
	if a in dancers:
		color = dancers[a]
		dancers[b] = (color + 1) % 3
		dancers[c] = (color + 2) % 3
	elif b in dancers:
		color = dancers[b]
		dancers[a] = (color + 1) % 3
		dancers[c] = (color + 2) % 3
	elif c in dancers:
		color = dancers[c]
		dancers[a] = (color + 1) % 3
		dancers[b] = (color + 2) % 3
	else:
		dancers[a] = 0
		dancers[b] = 1
		dancers[c] = 2
for i in range(n - 1):
	print(dancers[i + 1] + 1, end=' ')
print(dancers[n] + 1)


(n, m) = [int(x) for x in input().split()]
dancers = {}
for i in range(m):
	dance = [int(x) for x in input().split()]
	for j in range(3):
		if dance[j] not in dancers:
			dancers[dance[j]] = j
		else:
			dancers[dance[(j + 1) % 3]] = (dancers[dance[j]] + 1) % 3
			dancers[dance[(j + 2) % 3]] = (dancers[dance[j]] + 2) % 3
			break
print(*[x + 1 for x in list(dancers.values())])


(n, k) = map(int, input().split())
l = [0] * (n + 1)
for i in range(k):
	(a, b, c) = map(int, input().split())
	if l[a] == 0 and l[b] == 0 and (l[c] == 0):
		l[a] = 1
		l[b] = 2
		l[c] = 3
	elif l[a] != 0:
		x = l[a]
		if x == 1:
			l[b] = 2
			l[c] = 3
		elif x == 2:
			l[b] = 1
			l[c] = 3
		elif x == 3:
			l[b] = 2
			l[c] = 1
	elif l[b] != 0:
		x = l[b]
		if x == 1:
			l[a] = 2
			l[c] = 3
		elif x == 2:
			l[a] = 1
			l[c] = 3
		elif x == 3:
			l[a] = 2
			l[c] = 1
	elif l[c] != 0:
		x = l[c]
		if x == 1:
			l[b] = 2
			l[a] = 3
		elif x == 2:
			l[b] = 1
			l[a] = 3
		elif x == 3:
			l[b] = 2
			l[a] = 1
for i in l[1:]:
	print(i, end=' ')


(n, m) = map(int, input().split())
l = [0 for i in range(n + 1)]
for i in range(m):
	(x, y, z) = map(int, input().split())
	if l[x] + l[y] + l[z] == 0:
		l[x] = 1
		l[y] = 2
		l[z] = 3
	elif l[x]:
		if l[x] == 1:
			l[y] = 2
			l[z] = 3
		elif l[x] == 2:
			l[y] = 1
			l[z] = 3
		else:
			l[y] = 1
			l[z] = 2
	elif l[y]:
		if l[y] == 1:
			l[x] = 2
			l[z] = 3
		elif l[y] == 2:
			l[x] = 1
			l[z] = 3
		else:
			l[x] = 1
			l[z] = 2
	elif l[z] == 1:
		l[x] = 2
		l[y] = 3
	elif l[z] == 2:
		l[x] = 1
		l[y] = 3
	else:
		l[x] = 1
		l[y] = 2
for i in range(1, len(l)):
	print(l[i], end=' ')


(n, m) = map(int, input().split())
mat = [input().split() for _ in range(m)]
col = [-1 for _ in range(n)]
col[int(mat[0][0]) - 1] = 1
for d in mat:
	cols = [1, 2, 3]
	for x in d:
		if col[int(x) - 1] != -1:
			cols.remove(col[int(x) - 1])
	for x in d:
		if col[int(x) - 1] == -1:
			col[int(x) - 1] = cols[0]
			cols.remove(cols[0])
	prev = d
print(' '.join(map(str, col)))


(n, m) = map(int, input().split())
l = [0] * (n + 1)
for i in range(m):
	(a, b, c) = map(int, input().split())
	if l[a] != 0:
		if l[a] == 1:
			l[b] = 2
			l[c] = 3
		elif l[a] == 2:
			l[b] = 3
			l[c] = 1
		else:
			l[b] = 1
			l[c] = 2
	elif l[b] != 0:
		if l[b] == 1:
			l[c] = 2
			l[a] = 3
		elif l[b] == 2:
			l[c] = 3
			l[a] = 1
		else:
			l[c] = 1
			l[a] = 2
	elif l[c] != 0:
		if l[c] == 1:
			l[a] = 2
			l[b] = 3
		elif l[c] == 2:
			l[a] = 3
			l[b] = 1
		else:
			l[a] = 1
			l[b] = 2
	else:
		l[a] = 1
		l[b] = 2
		l[c] = 3
for i in range(1, n + 1):
	print(l[i], end=' ')


(dancers, dances) = map(int, input().split())
people = []
default = '1 2 3'
for x in range(dances):
	people.append(list(map(int, input().split())))
if dances * 3 == dancers:
	ans = []
	for x in range(dances):
		ans.append(1)
		ans.append(2)
		ans.append(3)
	ans.sort()
	print(*ans)
else:
	val1 = people[0][0]
	val2 = people[0][1]
	val3 = people[0][2]
	freq = {val1: 1, val2: 2, val3: 3}
	for x in range(1, dances):
		if people[x][0] in freq.keys():
			if freq[people[x][0]] == 1:
				freq[people[x][1]] = 2
				freq[people[x][2]] = 3
			elif freq[people[x][0]] == 2:
				freq[people[x][1]] = 1
				freq[people[x][2]] = 3
			else:
				freq[people[x][1]] = 1
				freq[people[x][2]] = 2
		elif people[x][1] in freq.keys():
			if freq[people[x][1]] == 1:
				freq[people[x][0]] = 2
				freq[people[x][2]] = 3
			elif freq[people[x][1]] == 2:
				freq[people[x][0]] = 1
				freq[people[x][2]] = 3
			else:
				freq[people[x][0]] = 1
				freq[people[x][2]] = 2
		elif people[x][2] in freq.keys():
			if freq[people[x][2]] == 1:
				freq[people[x][0]] = 2
				freq[people[x][1]] = 3
			elif freq[people[x][2]] == 2:
				freq[people[x][0]] = 1
				freq[people[x][1]] = 3
			else:
				freq[people[x][0]] = 1
				freq[people[x][1]] = 2
		else:
			freq[people[x][0]] = 1
			freq[people[x][1]] = 2
			freq[people[x][2]] = 3
	for x in range(dancers):
		print(freq[x + 1], end=' ')


(n, m) = map(int, input().split())
arr = []
for _ in range(m):
	(a, b, c) = map(int, input().split())
	arr.append([a, b, c])
p = []
for i in range(n + 1):
	p.append(0)
for i in range(m):
	ii = [1, 2, 3]
	if p[arr[i][0]] != 0:
		ii.remove(p[arr[i][0]])
	if p[arr[i][1]] != 0:
		ii.remove(p[arr[i][1]])
	if p[arr[i][2]] != 0:
		ii.remove(p[arr[i][2]])
	if p[arr[i][0]] == 0:
		p[arr[i][0]] = ii[0]
		ii.remove(ii[0])
	if p[arr[i][1]] == 0:
		p[arr[i][1]] = ii[0]
		ii.remove(ii[0])
	if p[arr[i][2]] == 0:
		p[arr[i][2]] = ii[0]
		ii.remove(ii[0])
for i in range(1, n + 1):
	print(p[i], end=' ')


(n, m) = map(int, input().split())
l = []
for i in range(m):
	l += [list(map(int, input().split()))]
a = ['e'] * (n + 1)
for i in l:
	t = [0] * 4
	for j in i:
		if a[j] != 'e':
			t[a[j]] = 1
	for j in i:
		if a[j] == 'e':
			for i in range(1, 4):
				if t[i] == 0:
					a[j] = i
					t[i] = 1
					break
		if sum(t) == 3:
			break
for i in range(1, n + 1):
	print(a[i], end=' ')


def main():
	(n, m) = map(int, input().split())
	a = [0 for i in range(n)]
	for _ in range(m):
		dp = []
		(m, n, p) = map(int, input().split())
		(m, n, p) = (m - 1, n - 1, p - 1)
		for i in range(1, 4):
			if a[m] != i and a[n] != i and (a[p] != i):
				dp.append(i)
		index = 0
		if a[m] == 0:
			a[m] = dp[index]
			index += 1
		if a[n] == 0:
			a[n] = dp[index]
			index += 1
		if a[p] == 0:
			a[p] = dp[index]
			index += 1
	for x in a:
		print(x, end=' ')
main()


(n, m) = map(int, input().split())
L = [0] * n
A = [1, 2, 3]
for i in range(m):
	(a, b, c) = map(int, input().split())
	if L[a - 1] in A or L[b - 1] in A or L[c - 1] in A:
		if L[a - 1] in A:
			x = L[a - 1]
			A.remove(x)
			L[b - 1] = A[0]
			L[c - 1] = A[1]
			A.append(x)
		elif L[b - 1] in A:
			x = L[b - 1]
			A.remove(x)
			L[a - 1] = A[0]
			L[c - 1] = A[1]
			A.append(x)
		elif L[c - 1] in A:
			x = L[c - 1]
			A.remove(x)
			L[a - 1] = A[0]
			L[b - 1] = A[1]
			A.append(x)
	else:
		L[a - 1] = A[0]
		L[b - 1] = A[1]
		L[c - 1] = A[2]
print(*L)


(n, m) = map(int, input().split())
colors = {}
for i in range(m):
	dancers = list(map(int, input().split()))
	avCols = {1, 2, 3}
	ans = 0
	for j in range(3):
		if dancers[j] in colors:
			avCols.remove(colors[dancers[j]])
			dancers.pop(j)
			break
	for j in range(len(dancers)):
		colors[dancers[j]] = avCols.pop()
for i in range(n):
	print(colors[i + 1], end=' ')


import os
import sys
from io import BytesIO, IOBase

def main():
	(n, m) = map(int, input().split())
	dp = [-1] * (n + 1)
	for _ in range(m):
		(x, y, z) = map(int, input().split())
		if dp[x] != -1:
			val = dp[x]
			if val == 1:
				dp[y] = 2
				dp[z] = 3
			elif val == 2:
				dp[y] = 1
				dp[z] = 3
			else:
				dp[y] = 1
				dp[z] = 2
		elif dp[y] != -1:
			val = dp[y]
			if val == 1:
				dp[x] = 2
				dp[z] = 3
			elif val == 2:
				dp[x] = 1
				dp[z] = 3
			else:
				dp[x] = 1
				dp[z] = 2
		elif dp[z] != -1:
			val = dp[z]
			if val == 1:
				dp[x] = 2
				dp[y] = 3
			elif val == 2:
				dp[x] = 1
				dp[y] = 3
			else:
				dp[x] = 1
				dp[y] = 2
		else:
			dp[x] = 1
			dp[y] = 2
			dp[z] = 3
	print(*dp[1:])

def nouse0():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse1():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse2():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def nouse3():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse4():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse5():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')
main()


(n, m) = list(map(int, input().split()))
dances = [list(map(int, input().split())) for _ in range(m)]
colors = [None for _ in range(n + 1)]
for dance in dances:
	available_colors = [3, 2, 1]
	for dancer in dance:
		color = colors[dancer]
		if color is not None:
			available_colors.remove(color)
	for dancer in dance:
		color = colors[dancer]
		if color is None:
			colors[dancer] = available_colors[-1]
			available_colors.pop()
for color in colors[1:]:
	print(color, end=' ')


from sys import *
input = lambda : stdin.readline()
int_arr = lambda : list(map(int, stdin.readline().strip().split()))
str_arr = lambda : list(map(str, stdin.readline().split()))
get_str = lambda : map(str, stdin.readline().strip().split())
get_int = lambda : map(int, stdin.readline().strip().split())
get_float = lambda : map(float, stdin.readline().strip().split())
mod = 1000000007
setrecursionlimit(1000)
(n, m) = get_int()
arr = []
for i in range(m):
	arr.append(sorted(int_arr()))
dic = {arr[0][0]: 1, arr[0][1]: 2, arr[0][2]: 3}
for i in range(1, len(arr)):
	if arr[i][0] in dic.keys():
		if dic[arr[i][0]] == 1:
			dic[arr[i][1]] = 2
			dic[arr[i][2]] = 3
		elif dic[arr[i][0]] == 2:
			dic[arr[i][1]] = 1
			dic[arr[i][2]] = 3
		else:
			dic[arr[i][1]] = 1
			dic[arr[i][2]] = 2
	elif arr[i][1] in dic.keys():
		if dic[arr[i][1]] == 1:
			dic[arr[i][0]] = 2
			dic[arr[i][2]] = 3
		elif dic[arr[i][1]] == 2:
			dic[arr[i][0]] = 1
			dic[arr[i][2]] = 3
		else:
			dic[arr[i][0]] = 1
			dic[arr[i][2]] = 2
	elif arr[i][2] in dic.keys():
		if dic[arr[i][2]] == 1:
			dic[arr[i][1]] = 2
			dic[arr[i][0]] = 3
		elif dic[arr[i][2]] == 2:
			dic[arr[i][1]] = 1
			dic[arr[i][0]] = 3
		else:
			dic[arr[i][1]] = 1
			dic[arr[i][0]] = 2
	else:
		dic[arr[i][0]] = 1
		dic[arr[i][1]] = 2
		dic[arr[i][2]] = 3
for i in range(1, n + 1):
	print(dic[i], end=' ')


import sys

def get_ints():
	return list(map(int, sys.stdin.readline().strip().split()))
temparr = get_ints()
dicts = {}
n = temparr[0]
m = temparr[1]
dicts = {}
for i in range(m):
	color = [1, 2, 3]
	arr = get_ints()
	first = arr[0]
	sec = arr[1]
	third = arr[2]
	firstflag = 0
	secflag = 0
	thirdflag = 0
	if first in dicts:
		val = dicts[first]
		color.remove(val)
		firstflag = 1
	if sec in dicts:
		val = dicts[sec]
		color.remove(val)
		secflag = 1
	if third in dicts:
		val = dicts[third]
		color.remove(val)
		thirdflag = 1
	if firstflag == 0:
		dicts[first] = color[0]
	if firstflag == 0 and secflag == 0:
		dicts[sec] = color[1]
	if firstflag == 0 and secflag == 0 and (thirdflag == 0):
		dicts[third] = color[2]
	if firstflag == 1 and secflag == 0:
		dicts[sec] = color[0]
	if firstflag == 1 and secflag == 0 and (thirdflag == 0):
		dicts[third] = color[1]
	if firstflag == 0 and secflag == 1:
		dicts[first] = color[0]
	if firstflag == 0 and secflag == 1 and (thirdflag == 0):
		dicts[third] = color[1]
	if firstflag == 1 and secflag == 0 and (thirdflag == 0):
		dicts[third] = color[1]
	if firstflag == 1 and secflag == 1 and (thirdflag == 0):
		dicts[third] = color[0]
ans = []
for (k, val) in sorted(dicts.items()):
	ans.append(str(val))
print(' '.join(ans))


from sys import stdin, stdout
stdin.readline

def mp():
	return list(map(int, stdin.readline().strip().split()))

def it():
	return int(stdin.readline().strip())
from collections import defaultdict as dd, Counter as C, deque
from math import ceil, gcd, sqrt, factorial, log2, floor
from bisect import bisect_right as br, bisect_left as bl
import heapq
(n, m) = mp()
d = dd(lambda : 0)
for _ in range(m):
	l = mp()
	s = set()
	s.add(1)
	s.add(2)
	s.add(3)
	for i in l:
		if d[i]:
			s.remove(d[i])
	for i in l:
		if s and (not d[i]):
			d[i] = s.pop()
for i in sorted(d.keys()):
	print(d[i], end=' ')


(n, m) = map(int, input().split())
p = [0] * (n + 1)
for i in range(m):
	(a, b, c) = map(int, input().split())
	if p[a] != 0:
		x = [1, 2, 3]
		x.remove(p[a])
		p[b] = x[0]
		p[c] = x[1]
	elif p[b] != 0:
		x = [1, 2, 3]
		x.remove(p[b])
		p[c] = x[0]
		p[a] = x[1]
	elif p[c] != 0:
		x = [1, 2, 3]
		x.remove(p[c])
		p[b] = x[0]
		p[a] = x[1]
	else:
		p[a] = 1
		p[b] = 2
		p[c] = 3
print(' '.join(map(str, p[1:])))


import sys
(nbDancers, nbDances) = list(map(int, sys.stdin.readline().split(' ')))
dancers = [0] * (nbDancers + 1)
for line in sys.stdin:
	taken = [False, False, False, False]
	ds = list(map(int, line.split(' ')))
	for d in ds:
		taken[dancers[d]] = True
	for d in ds:
		if dancers[d] == 0:
			if not taken[1]:
				dancers[d] = 1
				taken[1] = True
			elif not taken[2]:
				dancers[d] = 2
				taken[2] = True
			elif not taken[3]:
				dancers[d] = 3
				taken[3] = True
print(' '.join(map(str, dancers[1:])))


R = lambda : list(map(int, input().split()))
(n, m) = R()
color = [0] * n
for i in range(m):
	d = list(R())
	temp = 0
	for j in d:
		if color[j - 1] != 0:
			temp = temp | 1 << color[j - 1]
	for j in d:
		if color[j - 1] == 0:
			for k in range(3):
				if not 1 << k + 1 & temp:
					color[j - 1] = k + 1
					temp = temp | 1 << k + 1
					break
print(' '.join(map(str, color)))


(n, m) = map(int, input().split())
d = [0 for i in range(n)]
for i in range(m):
	(x, y, z) = map(int, input().split())
	x -= 1
	y -= 1
	z -= 1
	s = [[d[x], x], [d[y], y], [d[z], z]]
	s.sort()
	if s[2][0] == 0:
		d[x] = 1
		d[y] = 2
		d[z] = 3
	elif s[1][0] == 0:
		a = [s[2][0]]
		b = [s[2][1]]
		for j in [x, y, z]:
			for k in [1, 2, 3]:
				if j not in b and k not in a and (d[j] == 0):
					d[j] = k
					a.append(k)
					b.append(j)
	elif s[0][0] == 0:
		a = [s[2][0], s[1][0]]
		b = [s[2][1], s[1][1]]
		for j in [x, y, z]:
			for k in [1, 2, 3]:
				if j not in b and k not in a and (d[j] == 0):
					d[j] = k
					a.append(k)
					b.append(j)
	else:
		continue
for i in range(n):
	print(d[i], end=' ')


import sys

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
(n, m) = rinput()
A = []
for _ in range(m):
	A.append(rlinput())
ans = [0] * (n + 1)
for i in range(m):
	array = [ans[A[i][0]], ans[A[i][1]], ans[A[i][2]]]
	if array.count(0) == 3:
		ans[A[i][0]] = 1
		ans[A[i][1]] = 2
		ans[A[i][2]] = 3
	else:
		for j in range(3):
			if array[j] != 0:
				break
		p = set([1, 2, 3]) - set([array[j]])
		p = list(p)
		index = 0
		for k in range(3):
			if array[k] == 0:
				ans[A[i][k]] = p[index]
				index += 1
print(*ans[1:])


(n, m) = list(map(int, input().split()))
dic = dict(zip(range(1, n + 1), [0] * n))

def work(arr):
	s1 = set([1, 2, 3])
	s = set()
	for item in arr:
		s.add(dic[item])
	s1 = s1 - s
	for item in arr:
		if dic[item] == 0:
			dic[item] = s1.pop()
for i in range(m):
	arr = list(map(int, input().split()))
	work(arr)
for item in sorted(dic):
	print(dic[item], end=' ')


from math import gcd

def take_input(s):
	if s == 1:
		return int(input())
	return map(int, input().split())
(n, m) = take_input(2)
grid = []
d = {}
for i in range(m):
	grid += list(take_input(3))
for i in range(0, m * 3, 3):
	if d.get(grid[i], 0) > 0:
		if d.get(grid[i], 0) == 1:
			d[grid[i + 1]] = 2
			d[grid[i + 2]] = 3
		elif d.get(grid[i], 0) == 2:
			d[grid[i + 1]] = 1
			d[grid[i + 2]] = 3
		else:
			d[grid[i + 1]] = 1
			d[grid[i + 2]] = 2
	elif d.get(grid[i + 1], 0) > 0:
		if d.get(grid[i + 1], 0) == 1:
			d[grid[i]] = 2
			d[grid[i + 2]] = 3
		elif d.get(grid[i + 1], 0) == 2:
			d[grid[i]] = 1
			d[grid[i + 2]] = 3
		else:
			d[grid[i]] = 1
			d[grid[i + 2]] = 2
	elif d.get(grid[i + 2], 0) > 0:
		if d.get(grid[i + 2], 0) == 1:
			d[grid[i]] = 2
			d[grid[i + 1]] = 3
		elif d.get(grid[i + 2], 0) == 2:
			d[grid[i]] = 1
			d[grid[i + 1]] = 3
		else:
			d[grid[i]] = 1
			d[grid[i + 1]] = 2
	else:
		d[grid[i]] = 1
		d[grid[i + 1]] = 2
		d[grid[i + 2]] = 3
for i in range(n):
	print(d[i + 1], end=' ')


(n, m) = list(map(int, input().split()))
l = []
for i in range(m):
	l.append(list(map(int, input().split())))
d = {}
for i in range(m):
	for j in range(3):
		d[l[i][j]] = 0
for i in range(m):
	for j in range(3):
		if d[l[i][0]] + d[l[i][1]] + d[l[i][2]] == 0:
			d[l[i][j]] = j + 1
		else:
			x = [1, 2, 3]
			for j in range(3):
				if d[l[i][j]]:
					x.remove(d[l[i][j]])
			c = 0
			for j in range(3):
				if not d[l[i][j]]:
					d[l[i][j]] = x[c]
					c = c + 1
			break
for i in range(1, n):
	print(d[i], end=' ')
print(d[n])


(n, m) = map(int, input().split())
color = [0] * (n + 1)
for i in range(m):
	s = {1, 2, 3}
	(a, b, c) = map(int, input().split())
	s = s.difference({color[a], color[b], color[c]})
	for j in [a, b, c]:
		if color[j] == 0:
			color[j] = s.pop()
[print(c, end=' ') for c in color[1:]]


(n, m) = map(int, input().split())
dances = []
for _ in range(m):
	dances.append([int(x) - 1 for x in input().split()])
ans = [0] * n
for dance in dances:
	for i in range(len(dance)):
		if ans[dance[i]] == 0:
			for col in range(1, 4):
				ok = True
				for j in range(len(dance)):
					if ans[dance[j]] == col:
						ok = False
				if ok:
					ans[dance[i]] = col
					break
print(*ans)


(n, m) = map(int, input().split())
ans = [0] * (n + 1)
x = [1, 2, 3]
for i in range(m):
	q = 0
	(a, b, c) = map(int, input().split())
	if ans[a] == 0 and ans[b] == 0 and (ans[c] == 0):
		ans[a] = 1
		ans[b] = 2
		ans[c] = 3
	elif ans[a] != 0 or ans[b] != 0 or ans[c] != 0:
		r = list(set(x) - set([ans[a], ans[b], ans[c]]))
		if ans[a] == 0:
			ans[a] = r[q]
			q += 1
		if ans[b] == 0:
			ans[b] = r[q]
			q += 1
		if ans[c] == 0:
			ans[c] = r[q]
			q += 1
print(*ans[1:])


ds = {}
(a, b) = [int(x) for x in input().split(' ')]
for i in range(b):
	d = [int(x) for x in input().split(' ')]
	for j in range(3):
		if d[j] not in ds:
			ds[d[j]] = j
		else:
			ds[d[(j + 1) % 3]] = (ds[d[j]] + 1) % 3
			ds[d[(j + 2) % 3]] = (ds[d[j]] + 2) % 3
			break
print(*[x + 1 for x in ds.values()])


def dance(arr, n):
	ans = [None] * (n + 1)
	for i in range(len(arr)):
		color = [1, 2, 3]
		flag = False
		bad = None
		for j in range(3):
			if ans[arr[i][j]] != None:
				color.remove(ans[arr[i][j]])
				bad = j
		for x in range(3):
			if x != bad:
				ans[arr[i][x]] = color[0]
				color.pop(0)
	print(*ans[1:])
	return ''
(a, b) = map(int, input().strip().split())
blanck = []
for i in range(b):
	lst = list(map(int, input().strip().split()))
	blanck.append(lst)
print(dance(blanck, a))


from collections import defaultdict

def main():
	(n, m) = map(int, input().split(' '))
	colors = [0] * (n + 1)
	dances = []
	ma = defaultdict(int)
	for i in range(m):
		(a, b, c) = map(int, input().split(' '))
		if colors[a] > 0:
			colors[b] = 1 + colors[a] % 3
			colors[c] = 1 + (1 + colors[a] % 3) % 3
		elif colors[b] > 0:
			colors[a] = 1 + colors[b] % 3
			colors[c] = 1 + (1 + colors[b] % 3) % 3
		elif colors[c] > 0:
			colors[a] = 1 + colors[c] % 3
			colors[b] = 1 + (1 + colors[c] % 3) % 3
		else:
			colors[a] = 1
			colors[b] = 2
			colors[c] = 3
	print(' '.join(list(map(str, colors[1:]))))
main()


(n, m) = map(int, input().split())
l = [0] * (n + 1)
for _ in range(m):
	p = [1, 2, 3]
	arr = list(map(int, input().split()))
	for i in arr:
		if l[i] != 0:
			p.remove(l[i])
	for i in arr:
		if l[i] == 0:
			l[i] = p.pop()
for i in range(1, n + 1):
	print(l[i], end=' ')


(n, m) = map(int, input().split())
mp = {}
for _ in range(m):
	(a, b, c) = map(int, input().split())
	if b in mp:
		(a, b) = (b, a)
	elif c in mp:
		(a, c) = (c, a)
	if a in mp and mp[a] == 1:
		mp[b] = 2
		mp[c] = 3
	elif a in mp and mp[a] == 2:
		mp[b] = 1
		mp[c] = 3
	elif a in mp and mp[a] == 3:
		mp[b] = 1
		mp[c] = 2
	else:
		mp[a] = 1
		mp[b] = 2
		mp[c] = 3
for i in range(1, n + 1):
	print(mp[i], end=' ')


(n, m) = map(int, input().split())
red = set()
blue = set()
white = set()
for i in range(m):
	(x, y, z) = map(int, input().split())
	if x in white:
		if y in blue:
			if z not in red:
				red.add(z)
		elif y in red:
			if z not in blue:
				blue.add(z)
		elif z in blue:
			if y not in red:
				red.add(y)
		elif z in red:
			if y not in blue:
				blue.add(y)
		else:
			blue.add(y)
			red.add(z)
	elif x in red:
		if y in blue:
			if z not in white:
				white.add(z)
		elif y in white:
			if z not in blue:
				blue.add(z)
		elif z in white:
			if y not in blue:
				blue.add(y)
		elif z in blue:
			if y not in white:
				white.add(y)
		else:
			blue.add(y)
			white.add(z)
	elif x in blue:
		if y in white:
			if z not in red:
				red.add(z)
		elif y in red:
			if z not in white:
				white.add(z)
		elif z in white:
			if y not in red:
				red.add(y)
		elif z in red:
			if y not in white:
				white.add(y)
		else:
			white.add(y)
			red.add(z)
	elif y in red:
		if z in blue:
			white.add(x)
		elif z in white:
			blue.add(x)
		else:
			white.add(x)
			blue.add(z)
	elif y in white:
		if z in blue:
			red.add(x)
		elif z in red:
			blue.add(x)
		else:
			blue.add(x)
			red.add(z)
	elif y in blue:
		if z in red:
			white.add(x)
		elif z in white:
			red.add(x)
		else:
			red.add(x)
			white.add(z)
	elif z in red:
		white.add(x)
		blue.add(y)
	elif z in white:
		red.add(x)
		blue.add(y)
	elif z in blue:
		red.add(x)
		white.add(y)
	else:
		white.add(x)
		red.add(y)
		blue.add(z)
for i in range(1, n + 1):
	if i in white:
		print(1, end=' ')
	elif i in red:
		print(2, end=' ')
	else:
		print(3, end=' ')


import sys
(nbDancers, nbDances) = map(int, sys.stdin.readline().split(' '))
dancers = [0] * (nbDancers + 1)
for line in sys.stdin:
	taken = [False, False, False, False]
	ds = list(map(int, line.split(' ')))
	for d in ds:
		taken[dancers[d]] = True
	for d in ds:
		if dancers[d] == 0:
			iCurr = 1
			while iCurr <= 3 and taken[iCurr]:
				iCurr += 1
			dancers[d] = iCurr
			taken[iCurr] = True
print(' '.join(map(str, dancers[1:])))


l = lambda : map(int, input().split())
(n, m) = map(int, input().split())
d = {}
s = ''
for _ in ' ' * m:
	c = [1, 2, 3]
	D = list(l())
	for i in D:
		if i in d:
			if d[i] in c:
				c.remove(d[i])
			D.remove(i)
	for i in D:
		d[i] = c.pop(0)
print(' '.join((str(d[i]) for i in sorted(d))))


(n, m) = list(map(int, input().split()))
colors = [0] * n
for i in range(m):
	choices = [1, 2, 3]
	dancers = list(map(int, input().split()))
	for a in dancers:
		try:
			choices.remove(colors[a - 1])
		except:
			pass
	for a in dancers:
		if colors[a - 1] == 0:
			colors[a - 1] = choices[0]
			choices.remove(colors[a - 1])
print(*colors)


def __starting_point():
	(n, m) = map(int, input().split())
	color = dict()
	for i in range(m):
		d = list(map(int, input().split()))
		temp = dict()
		for j in range(3):
			if d[j] in color:
				temp[color[d[j]]] = 1
		for j in range(3):
			if d[j] not in color:
				for k in range(3):
					if k + 1 not in temp:
						color[d[j]] = k + 1
						temp[k + 1] = 1
						break
	for i in range(n):
		print(color[i + 1], end=' ')
	print()
__starting_point()


(n, m) = map(int, input().split())
a = []
d = {}
for i in range(m):
	a.append(list(map(int, input().split())))
for i in range(m):
	ex = n + 1
	f = n + 1
	for j in range(3):
		if a[i][j] in d:
			ex = a[i][j]
			f = d[a[i][j]]
			break
	t = 1
	for j in range(3):
		if ex == a[i][j]:
			continue
		if t == f:
			t = (t + 1) % 4
		d[a[i][j]] = t
		t = (t + 1) % 4
for i in range(0, n):
	print(d[i + 1], end=' ')


def main():
	(n, m) = map(int, input().split())
	r = [0] * (n + 1)
	for _ in range(m):
		(a, b, c) = map(int, input().split())
		(r[a], r[b], r[c]) = {(0, 0, 0): (1, 2, 3), (0, 0, 1): (2, 3, 1), (0, 0, 2): (1, 3, 2), (0, 0, 3): (1, 2, 3), (0, 1, 0): (2, 1, 3), (0, 1, 2): (3, 1, 2), (0, 1, 3): (2, 1, 3), (0, 2, 0): (1, 2, 3), (0, 2, 1): (3, 2, 1), (0, 2, 3): (1, 2, 3), (0, 3, 0): (1, 3, 2), (0, 3, 1): (2, 3, 1), (0, 3, 2): (1, 3, 2), (1, 0, 0): (1, 2, 3), (1, 0, 2): (1, 3, 2), (1, 0, 3): (1, 2, 3), (1, 2, 0): (1, 2, 3), (1, 2, 3): (1, 2, 3), (1, 3, 0): (1, 3, 2), (1, 3, 2): (1, 3, 2), (2, 0, 0): (2, 1, 3), (2, 0, 1): (2, 3, 1), (2, 0, 3): (2, 1, 3), (2, 1, 0): (2, 1, 3), (2, 1, 3): (2, 1, 3), (2, 3, 0): (2, 3, 1), (2, 3, 1): (2, 3, 1), (3, 0, 0): (3, 1, 2), (3, 0, 1): (3, 2, 1), (3, 0, 2): (3, 1, 2), (3, 1, 0): (3, 1, 2), (3, 1, 2): (3, 1, 2), (3, 2, 0): (3, 2, 1), (3, 2, 1): (3, 2, 1)}[r[a], r[b], r[c]]
	print(' '.join(((None, '1', '2', '3')[x] for x in r[1:])))
main()


import sys
(x, n) = map(int, input().split())
d = {}
for i in range(n):
	a = list(map(int, input().split()))
	b = [1, 2, 3]
	rf = bf = wf = 0
	for j in a:
		if j in d:
			b.remove(d[j])
			a.remove(j)
	if len(b) != 0:
		for j in range(len(a)):
			d[a[j]] = b[j]
for i in range(1, len(d) + 1):
	sys.stdout.write(str(d[i]) + ' ')


(n, m) = list(map(int, input().split()))
a = [0] * n
for i in range(m):
	s = list(map(int, input().split()))
	for j in range(1, 4):
		if a[s[j - 1] - 1] != 0:
			a[s[a[s[j - 1] - 1] - 1] - 1] = j
		else:
			a[s[j - 1] - 1] = j
print(' '.join(map(str, a)))


(n, m) = list(map(int, input().split()))
met = {}
for _ in range(m):
	arr = list(map(int, input().split()))
	if _ == 0:
		met[arr[0]] = 1
		met[arr[1]] = 2
		met[arr[2]] = 3
	else:
		arr2 = [1, 2, 3]
		xxx = 0
		for k in range(3):
			if arr[k] in met:
				arr2.remove(met[arr[k]])
		for k in range(3):
			if arr[k] not in met:
				met[arr[k]] = arr2[xxx]
				xxx += 1
for kkk in range(1, n + 1):
	print(met[kkk], end=' ')


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return map(int, input().split())

def array():
	return [int(i) for i in input().split()]
(n, m) = value()
dance = []
color = defaultdict(int)
for i in range(m):
	(a, b, c) = value()
	dance.append((a, b, c))
color[dance[0][0]] = 1
color[dance[0][1]] = 2
color[dance[0][2]] = 3
for i in dance[1:]:
	f = 0
	for j in i:
		if color[j] != 0:
			f = 1
			com = j
			break
	if f == 0:
		color[i[0]] = 1
		color[i[1]] = 2
		color[i[2]] = 3
	else:
		col = color[com] - 1
		for j in i:
			if j != com:
				col = (col + 1) % 3
				color[j] = col + 1
for i in range(1, n + 1):
	print(color[i], end=' ')


(n, m) = map(int, input().split())
d = [1] * n
s = set()
for i in range(m):
	(a, b, c) = map(int, input().split())
	if a - 1 in s:
		if d[a - 1] == 1:
			d[b - 1] = 2
			d[c - 1] = 3
		if d[a - 1] == 2:
			d[b - 1] = 1
			d[c - 1] = 3
		if d[a - 1] == 3:
			d[b - 1] = 1
			d[c - 1] = 2
	if b - 1 in s:
		if d[b - 1] == 1:
			d[a - 1] = 2
			d[c - 1] = 3
		if d[b - 1] == 2:
			d[a - 1] = 1
			d[c - 1] = 3
		if d[b - 1] == 3:
			d[a - 1] = 1
			d[c - 1] = 2
	if c - 1 in s:
		if d[c - 1] == 1:
			d[b - 1] = 2
			d[a - 1] = 3
		if d[c - 1] == 2:
			d[b - 1] = 1
			d[a - 1] = 3
		if d[c - 1] == 3:
			d[b - 1] = 1
			d[a - 1] = 2
	if a - 1 not in s and b - 1 not in s and (c - 1 not in s):
		d[a - 1] = 1
		d[b - 1] = 2
		d[c - 1] = 3
	s.add(a - 1)
	s.add(b - 1)
	s.add(c - 1)
print(*d)


def zip_sorted(a, b):
	(a, b) = zip(*sorted(zip(a, b)))
	sorted(zip(a, b), key=lambda x: x[1])
	return (a, b)
import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
S = lambda : list(map(str, input().split()))
(n, m) = I()
w = [0] * m
r = [0] * m
b = [0] * m
w1 = [0] * (n + 1)
for i in range(m):
	(w[i], r[i], b[i]) = I()
	if w1[w[i]] == 0:
		for j in range(1, 4):
			if w1[w[i]] == j or w1[r[i]] == j or w1[b[i]] == j:
				pass
			else:
				w1[w[i]] = j
				break
	if w1[r[i]] == 0:
		for j in range(1, 4):
			if w1[w[i]] == j or w1[r[i]] == j or w1[b[i]] == j:
				pass
			else:
				w1[r[i]] = j
				break
	if w1[b[i]] == 0:
		for j in range(1, 4):
			if w1[w[i]] == j or w1[r[i]] == j or w1[b[i]] == j:
				pass
			else:
				w1[b[i]] = j
				break
print(*w1[1:])


(n, m) = map(int, input().split(' '))
cl = [0] * (n + 1)
for i in range(m):
	(x, y, z) = list(map(int, input().split(' ')))
	if i == 0 or (cl[x] == 0 and cl[y] == 0 and (cl[z] == 0)):
		cl[x] = 1
		cl[y] = 2
		cl[z] = 3
	elif cl[x] != 0:
		if cl[x] == 1:
			(cl[y], cl[z]) = (2, 3)
		elif cl[x] == 2:
			(cl[y], cl[z]) = (1, 3)
		else:
			(cl[y], cl[z]) = (1, 2)
	elif cl[y] != 0:
		if cl[y] == 1:
			(cl[x], cl[z]) = (2, 3)
		elif cl[y] == 2:
			(cl[x], cl[z]) = (1, 3)
		else:
			(cl[x], cl[z]) = (1, 2)
	elif cl[z] != 0:
		if cl[z] == 1:
			(cl[y], cl[x]) = (2, 3)
		elif cl[z] == 2:
			(cl[y], cl[x]) = (1, 3)
		else:
			(cl[y], cl[x]) = (1, 2)
cl = [str(i) for i in cl]
print(' '.join(cl[1:]))


def solve(n, dances):
	k = [0] * (n + 1)
	for d in dances:
		for (i, x) in enumerate(d):
			color = k[x]
			if color != 0:
				k[d[color - 1]] = i + 1
			else:
				k[x] = i + 1
	return ' '.join([str(k[i]) for i in range(1, n + 1)])
f = lambda : list(map(int, input().split()))
(n, m) = f()
res = solve(n, [f() for _ in range(m)])
print(res)


import sys
sys.setrecursionlimit(10000)
(n, m) = [int(x) for x in input().strip().split()]
s = []
for i in range(m):
	(a, b, c) = [int(x) for x in input().strip().split()]
	s.append([a, b, c])
c = [0] * (n + 2)
alpha = [1, 2, 3]
for i in range(m):
	alpha = [1, 2, 3]
	k = s[i]
	index = -1
	for j in range(3):
		if c[k[j]] != 0:
			index = j
			break
	if index != -1:
		alpha.pop(c[k[index]] - 1)
	for j in range(3):
		if j != index:
			c[k[j]] = alpha.pop(0)
print(' '.join([str(x) for x in c[1:-1]]))


(n, m) = map(int, input().split())
dances = []
for i in range(m):
	dances.append(sorted([int(i) for i in input().split()]))
dancers = [0] * (n + 1)
for i in range(m):
	possible = [1, 2, 3]
	dance = dances[i]
	for dancer in dance:
		if dancers[dancer] != 0:
			possible.remove(dancers[dancer])
	for dancer in dance:
		if dancers[dancer] == 0:
			dancers[dancer] = possible.pop(0)
print(' '.join([str(i) for i in dancers[1:]]))


from collections import defaultdict
(n, m) = map(int, input().split())
k = defaultdict(lambda : 0)
for _ in range(m):
	t = [3, 2, 1]
	people = list(map(int, input().split()))
	ans = []
	for i in people:
		if i in k:
			t.remove(k[i])
			people.remove(i)
	for i in people:
		k[i] = t.pop()
for i in sorted(k.keys()):
	print(k[i], end=' ')


(n, m) = map(int, input().split())
d = [-1 for i in range(n + 1)]
for _ in range(m):
	p = {1, 2, 3}
	t = list(map(int, input().split()))
	for i in t:
		if d[i] != -1:
			p.discard(d[i])
	for i in t:
		if d[i] == -1:
			d[i] = p.pop()
for j in range(1, n + 1):
	print(d[j], end=' ')


def mi():
	return map(int, input().split())
(n, m) = mi()
c = [0] * n
for _ in range(m):
	(q, w, e) = mi()
	q -= 1
	w -= 1
	e -= 1
	if c[q] + c[w] + c[e] == 0:
		(c[q], c[w], c[e]) = (1, 2, 3)
	elif c[q] + c[w] == 0:
		if c[e] == 1:
			(c[q], c[w]) = (2, 3)
		elif c[e] == 2:
			(c[q], c[w]) = (1, 3)
		else:
			(c[q], c[w]) = (1, 2)
	elif c[e] + c[w] == 0:
		if c[q] == 1:
			(c[e], c[w]) = (2, 3)
		elif c[q] == 2:
			(c[e], c[w]) = (1, 3)
		else:
			(c[e], c[w]) = (1, 2)
	elif c[q] + c[e] == 0:
		if c[w] == 1:
			(c[q], c[e]) = (2, 3)
		elif c[w] == 2:
			(c[q], c[e]) = (1, 3)
		else:
			(c[q], c[e]) = (1, 2)
	elif c[q] == 0:
		c[q] = 6 - c[w] - c[e]
	elif c[w] == 0:
		c[w] = 6 - c[q] - c[e]
	elif c[e] == 0:
		c[e] = 6 - c[q] - c[w]
print(*c)


(n, M) = [int(x) for x in input().split()]
m = []
for i in range(M):
	a = list(map(int, input().split()))
	m.append(a)
d = dict()
for i in range(1, n + 1):
	d[i] = -1
for i in range(M):
	w = r = b = 0
	for j in range(3):
		num = m[i][j]
		if d[num] == -1:
			continue
		elif d[num] == 'w':
			w = 1
		elif d[num] == 'r':
			r = 1
		else:
			b = 1
	for j in range(3):
		num = m[i][j]
		if d[num] == -1:
			if w == 0:
				w = 1
				d[num] = 'w'
			elif r == 0:
				r = 1
				d[num] = 'r'
			else:
				b = 1
				d[num] = 'b'
		elif d[num] == 'w':
			w = 1
		elif d[num] == 'r':
			r = 1
		else:
			b = 1
ans = []
for (key, value) in d.items():
	if value == 'w':
		ans.append(1)
	elif value == 'r':
		ans.append(2)
	else:
		ans.append(3)
print(*ans)


(n, m) = map(int, input().split())
d = {}
for i in range(m):
	(x, y, z) = list(map(int, input().split()))
	if i == 0:
		d[x] = 1
		d[y] = 2
		d[z] = 3
	elif x in d:
		t1 = d[x]
		if t1 == 1:
			d[y] = 2
			d[z] = 3
		elif t1 == 2:
			d[y] = 1
			d[z] = 3
		elif t1 == 3:
			d[y] = 1
			d[z] = 2
	elif y in d:
		t1 = d[y]
		if t1 == 1:
			d[x] = 2
			d[z] = 3
		elif t1 == 2:
			d[x] = 1
			d[z] = 3
		elif t1 == 3:
			d[x] = 1
			d[z] = 2
	elif z in d:
		t1 = d[z]
		if t1 == 1:
			d[y] = 2
			d[x] = 3
		elif t1 == 2:
			d[y] = 1
			d[x] = 3
		elif t1 == 3:
			d[y] = 1
			d[x] = 2
	else:
		d[x] = 1
		d[y] = 2
		d[z] = 3
for i in range(n):
	print(d[i + 1], end=' ')


(n, m) = map(int, input().split())
ans = [-1] * (n + 1)
for k in range(m):
	dancers = list(map(int, input().split()))
	need = [1, 2, 3]
	for i in dancers:
		if ans[i] != -1:
			need.remove(ans[i])
	for i in dancers:
		if ans[i] == -1:
			ans[i] = need.pop(-1)
print(*ans[1:])


def __starting_point():
	(n, m) = input().split()
	(n, m) = (int(n), int(m))
	d = []
	color = dict()
	for i in range(m):
		d.append(input().split())
	for i in range(len(d)):
		for j in range(len(d[i])):
			d[i][j] = int(d[i][j])
	for i in range(m):
		if i == 0:
			for j in range(3):
				color[d[i][j]] = j + 1
		else:
			temp = dict()
			for j in range(3):
				if d[i][j] in color:
					temp[color[d[i][j]]] = 1
			for j in range(3):
				if d[i][j] not in color:
					for k in range(3):
						if k + 1 not in temp:
							color[d[i][j]] = k + 1
							temp[k + 1] = 1
							break
	for i in range(n):
		print(color[i + 1], end=' ')
	print()
__starting_point()


(n, m) = map(int, input().split())
li = []
for i in range(m):
	li.append([int(x) for x in input().split()])
d = {}
for i in range(m):
	x = li[i]
	use = [True] * 3
	l = []
	for ele in x:
		if d.get(ele, 0) != 0:
			use[d.get(ele) - 1] = False
	for i in range(3):
		if use[i] == True:
			l.append(i)
	for ele in x:
		if d.get(ele, 0) == 0:
			d[ele] = l.pop() + 1
for ele in sorted(d):
	print(d[ele], end=' ')


(a, b) = map(int, input().split())
l = {}
for i in range(a):
	l[i + 1] = 0
for i in range(b):
	(c, d, e) = map(int, input().split())
	if l[c] == 1:
		(l[d], l[e]) = (2, 3)
	elif l[c] == 2:
		(l[d], l[e]) = (1, 3)
	elif l[c] == 3:
		(l[d], l[e]) = (1, 2)
	elif l[d] == 1:
		(l[c], l[e]) = (2, 3)
	elif l[d] == 2:
		(l[c], l[e]) = (1, 3)
	elif l[d] == 3:
		(l[c], l[e]) = (1, 2)
	elif l[e] == 1:
		(l[c], l[d]) = (2, 3)
	elif l[e] == 2:
		(l[c], l[d]) = (1, 3)
	elif l[e] == 3:
		(l[c], l[d]) = (1, 2)
	else:
		(l[c], l[d], l[e]) = (1, 2, 3)
for i in range(a):
	print(l[i + 1], end=' ')


data = input().split(' ')
dances = int(data[1])
totalDancers = int(data[0])
dict = {}
for d in range(dances):
	dancers = input().split(' ')
	dancers = [int(x) for x in dancers]
	i = 0
	while i < 3:
		dict.setdefault(dancers[i], i)
		if dancers[i] in dict:
			if dict[dancers[i]] != i:
				(dancers[dict[dancers[i]]], dancers[i]) = (dancers[i], dancers[dict[dancers[i]]])
				dict[dancers[i]] = i
		else:
			dict.setdefault(dancers[i], i)
		i += 1
ans = ''
for i in range(1, totalDancers):
	ans = ans + str(dict[i] + 1) + ' '
ans = ans + str(dict[totalDancers] + 1)
print(ans)


(n, m) = map(int, input().split(' '))
(result, participated) = ([None] * n, {})
for x in range(m):
	dancers = [int(i) for i in input().split(' ')]
	(colors, temp) = (set([1, 2, 3]), -1)
	for d in range(3):
		if dancers[d] in participated:
			colors.remove(participated[dancers[d]])
			temp = d
	it = iter(colors)
	for i in range(3):
		t = dancers[i]
		if i != temp:
			result[dancers[i] - 1] = next(it)
			participated[t] = result[dancers[i] - 1]
print(*result)


(n, m) = map(int, input().split())
hash = {}
seti = set()
for i in range(m):
	(a, b, c) = map(int, input().split())
	if a not in seti and b not in seti and (c not in seti):
		hash[a] = 1
		hash[b] = 2
		hash[c] = 3
		seti.add(a)
		seti.add(b)
		seti.add(c)
	elif a in seti:
		if hash[a] == 1:
			hash[b] = 2
			hash[c] = 3
		if hash[a] == 2:
			hash[b] = 1
			hash[c] = 3
		if hash[a] == 3:
			hash[b] = 1
			hash[c] = 2
		seti.add(a)
		seti.add(b)
		seti.add(c)
	elif b in seti:
		if hash[b] == 1:
			hash[a] = 2
			hash[c] = 3
		if hash[b] == 2:
			hash[a] = 1
			hash[c] = 3
		if hash[b] == 3:
			hash[a] = 1
			hash[c] = 2
		seti.add(a)
		seti.add(b)
		seti.add(c)
	elif c in seti:
		if hash[c] == 1:
			hash[b] = 2
			hash[a] = 3
		if hash[c] == 2:
			hash[b] = 1
			hash[a] = 3
		if hash[c] == 3:
			hash[b] = 1
			hash[a] = 2
		seti.add(a)
		seti.add(b)
		seti.add(c)
l = list(sorted(hash.keys()))
for i in l:
	print(hash[i], end=' ')


import sys
(n, m) = list(map(int, sys.stdin.readline().split()))
Colors = [0] * (n + 1)
for i in range(m):
	(a, b, c) = list(map(int, sys.stdin.readline().split()))
	Z = [a, b, c]
	Q = [1, 2, 3]
	if Colors[a] != 0:
		Z.remove(a)
		Q.remove(Colors[a])
	if Colors[b] != 0:
		Z.remove(b)
		Q.remove(Colors[b])
	if Colors[c] != 0:
		Z.remove(c)
		Q.remove(Colors[c])
	for i in range(len(Z)):
		Colors[Z[i]] = Q[i]
Ans = ''
Ans += str(Colors[1])
for i in range(2, n + 1):
	Ans += ' ' + str(Colors[i])
sys.stdout.write(Ans)


(n, m) = map(int, input().split())
t = [0] * (n + 1)
for i in range(m):
	(a, b, c) = map(int, input().split())
	if t[a]:
		if t[a] == '1':
			(t[b], t[c]) = ('2', '3')
		elif t[a] == '2':
			(t[b], t[c]) = ('1', '3')
		else:
			(t[b], t[c]) = ('1', '2')
	elif t[b]:
		if t[b] == '1':
			(t[a], t[c]) = ('2', '3')
		elif t[b] == '2':
			(t[a], t[c]) = ('1', '3')
		else:
			(t[a], t[c]) = ('1', '2')
	elif t[c]:
		if t[c] == '1':
			(t[a], t[b]) = ('2', '3')
		elif t[c] == '2':
			(t[a], t[b]) = ('1', '3')
		else:
			(t[a], t[b]) = ('1', '2')
	else:
		(t[a], t[b], t[c]) = ('1', '2', '3')
print(' '.join(t[1:]))


c = lambda : list(map(int, input().split()))
(n, m) = c()
a = [0] * (n + 1)
for i in range(m):
	x = c()
	if any((a[i] for i in x)):
		d = [0] * 4
		d[sum((a[i] for i in x))] = 1
		for k in range(3):
			if not a[x[k]]:
				for j in range(1, 4):
					if not d[j]:
						a[x[k]] = j
						d[j] = 1
						break
	else:
		for j in range(3):
			a[x[j]] = j + 1
print(*a[1:])


import sys
import math

class DictList(dict):

	def __setitem__(self, key, value):
		try:
			self[key].append(value)
		except KeyError:
			super(DictList, self).__setitem__(key, value)
		except AttributeError:
			super(DictList, self).__setitem__(key, [self[key], value])

def fn(n, m, a):
	if n >= 3 * m:
		for i in range(3 * m):
			a[i] = [a[i], i % 3 + 1]
		a.sort()
		for i in range(n):
			print(a[i][1], end=' ')
	else:
		m1 = [[0] * 3 for i in range(m)]
		k = 0
		for i in range(m):
			for j in range(3):
				m1[i][j] = a[k]
				k = k + 1
		c = dict()
		k = 0
		for i in range(m):
			for j in range(3):
				if m1[i][j] in c:
					if j == 0:
						k1 = 1
						k2 = 2
					elif j == 1:
						k1 = 0
						k2 = 2
					elif j == 2:
						k1 = 0
						k2 = 1
					c[m1[i][k1]] = c[m1[i][j]] + 1
					c[m1[i][k2]] = c[m1[i][j]] + 2
					break
				else:
					c[m1[i][j]] = j % 3 + 1
		for i in range(n):
			if c[i + 1] > 3:
				c[i + 1] = c[i + 1] % 3
			if c[i + 1] == 0:
				c[i + 1] = 3
			print(c[i + 1], end=' ')
input = sys.stdin.read()
data = list(map(int, input.split()))
n = data[0]
m = data[1]
a = data[2:]
fn(n, m, a)


(n, m) = map(int, input().split())
arr = [0] * (n + 1)
for i in range(m):
	(a, b, c) = map(int, input().split())
	if arr[a] == 0 and arr[b] == 0 and (arr[c] == 0):
		arr[a] = 1
		arr[b] = 2
		arr[c] = 3
	else:
		brr = [1, 2, 3]
		if arr[a] != 0:
			brr.remove(arr[a])
		if arr[b] != 0:
			brr.remove(arr[b])
		if arr[c] != 0:
			brr.remove(arr[c])
		if arr[a] == 0:
			arr[a] = brr[0]
			brr.remove(brr[0])
		if arr[b] == 0:
			arr[b] = brr[0]
			brr.remove(brr[0])
		if arr[c] == 0:
			arr[c] = brr[0]
			brr.remove(brr[0])
print(*arr[1:])


def dancers(n, m, arr):
	dancers = [0] * (n + 1)
	for each in arr:
		current = [1, 2, 3]
		for i in each:
			if dancers[i] != 0:
				current.remove(dancers[i])
		for i in each:
			if dancers[i] == 0:
				dancers[i] = current[0]
				current.pop(0)
	for i in range(1, n + 1):
		print(dancers[i], end=' ')
(n, m) = map(int, input().split())
l = []
for i in range(m):
	l.append(list(map(int, input().split())))
dancers(n, m, l)


import sys
import heapq
from math import *
from collections import defaultdict as dd
from collections import deque
from collections import Counter as c
from itertools import combinations as comb
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(var)

def l():
	return list(map(int, data().split()))

def sl():
	return list(map(str, data().split()))

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [[val for i in range(n)] for j in range(m)]
(n, m) = sp()
answer = l1d(n, 1)
occur = set()
for i in range(m):
	(a, b, c) = sp()
	if i == 0:
		answer[b - 1] = 2
		answer[c - 1] = 3
	elif a in occur and b in occur and (c in occur):
		temp = 'do nothing'
	elif a in occur and b in occur:
		answer[c - 1] = 6 - (answer[a - 1] + answer[b - 1])
	elif a in occur and c in occur:
		answer[b - 1] = 6 - (answer[a - 1] + answer[c - 1])
	elif b in occur and c in occur:
		answer[a - 1] = 6 - (answer[b - 1] + answer[c - 1])
	elif a in occur:
		answer[b - 1] = answer[a - 1] % 3 + 1
		answer[c - 1] = 6 - (answer[b - 1] + answer[a - 1])
	elif b in occur:
		answer[a - 1] = answer[b - 1] % 3 + 1
		answer[c - 1] = 6 - (answer[b - 1] + answer[a - 1])
	elif c in occur:
		answer[b - 1] = answer[c - 1] % 3 + 1
		answer[a - 1] = 6 - (answer[b - 1] + answer[c - 1])
	else:
		answer[b - 1] = 2
		answer[c - 1] = 3
	occur.add(a)
	occur.add(b)
	occur.add(c)
print(*answer)


(n, m) = map(int, input().split())
dances = []
colors = [0] * (n + 1)
for _ in range(m):
	(temp1, temp2, temp3) = map(int, input().split())
	dances.append([temp1, temp2, temp3])
i = 0
while i < len(dances):
	check = ['w', 'r', 'b']
	for j in range(len(check)):
		if colors[dances[i][0]] == check[j]:
			check[j] = -1
			break
		elif colors[dances[i][1]] == check[j]:
			check[j] = -1
			break
		elif colors[dances[i][2]] == check[j]:
			check[j] = -1
			break
	for j in range(len(dances[i])):
		if colors[dances[i][j]] == 0:
			if check[0] != -1:
				colors[dances[i][j]] = check[0]
				check[0] = -1
			elif check[1] != -1:
				colors[dances[i][j]] = check[1]
				check[1] = -1
			else:
				colors[dances[i][j]] = check[2]
				check[2] = -1
	i += 1
for i in range(1, len(colors)):
	if colors[i] == 'w':
		print(1, end=' ')
	elif colors[i] == 'r':
		print(2, end=' ')
	else:
		print(3, end=' ')


def intinp():
	return list(map(int, input().split()))
(n, m) = intinp()
Color = [0 for i in range(n + 1)]
for i in range(m):
	u = [0]
	u = u + intinp()
	if Color[u[1]]:
		(u[Color[u[1]]], u[1]) = (u[1], u[Color[u[1]]])
	if Color[u[2]]:
		(u[Color[u[2]]], u[2]) = (u[2], u[Color[u[2]]])
	if Color[u[3]]:
		(u[Color[u[3]]], u[3]) = (u[3], u[Color[u[3]]])
	Color[u[1]] = 1
	Color[u[2]] = 2
	Color[u[3]] = 3
print(' '.join(list(map(str, Color[1:]))))


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
try:
	sys.setrecursionlimit(int(pow(10, 6)))
	sys.stdin = open('input.txt', 'r')
except:
	pass
(n, m) = L()
A = [L() for i in range(m)]
col = [-1 for i in range(n + 1)]
for (x, y, z) in A:
	cur = [col[x], col[y], col[z]]
	if cur.count(-1) == 3:
		col[x] = 1
		col[y] = 2
		col[z] = 3
	elif cur.count(-1) == 2:
		for pres in [1, 2, 3]:
			if pres in cur:
				continue
			for i in range(3):
				if i == 0 and cur[i] == -1:
					col[x] = pres
					cur[i] = pres
					break
				elif i == 1 and cur[i] == -1:
					col[y] = pres
					cur[i] = pres
					break
				elif i == 2 and cur[i] == -1:
					col[z] = pres
					cur[i] = pres
					break
	elif cur.count(-1) == 1:
		rem = sum(cur) + 1
		if cur[0] == -1:
			col[x] = 6 - rem
		elif cur[1] == -1:
			col[y] = 6 - rem
		else:
			col[z] = 6 - rem
for i in range(1, n + 1):
	if col[i] == -1:
		col[i] = 1
print(*col[1:])
endtime = time.time()


import sys, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
from itertools import permutations
import heapq
I = sys.stdin.readline
alpha = 'abcdefghijklmnopqrstuvwxyz'
mod = 10 ** 9 + 7

def ii():
	return int(I().strip())

def li():
	return list(map(int, I().strip().split()))

def mi():
	return map(int, I().strip().split())

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def ispali(s):
	i = 0
	j = len(s) - 1
	while i < j:
		if s[i] != s[j]:
			return False
		i += 1
		j -= 1
	return True

def isPrime(n):
	if n <= 1:
		return False
	elif n <= 2:
		return True
	else:
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				return False
		return True

def main():
	(n, m) = mi()
	d = defaultdict(int)
	for i in range(m):
		(a, b, c) = mi()
		color = [0, 1, 2, 3]
		if d[a] != 0:
			color[d[a]] = -1
		if d[b] != 0:
			color[d[b]] = -1
		if d[c] != 0:
			color[d[c]] = -1
		for dancer in [a, b, c]:
			if d[dancer] == 0:
				for c in range(1, 4):
					if color[c] != -1:
						d[dancer] = c
						color[c] = -1
						break
	ans = []
	for i in range(1, n + 1):
		if d[i] == 0:
			ans.append(1)
		else:
			ans.append(d[i])
	print(*ans)
main()


(n, m) = map(int, input().split())
a = []
for i in range(m):
	a.append(list(map(int, input().split())))
c = [0] * (n + 1)
for k in range(m):
	for i in range(3):
		if c[a[k][i]] == 1:
			c[a[k][(i + 1) % 3]] = 2
			c[a[k][(i + 2) % 3]] = 3
			break
		elif c[a[k][i]] == 2:
			c[a[k][(i + 1) % 3]] = 1
			c[a[k][(i + 2) % 3]] = 3
			break
		elif c[a[k][i]] == 3:
			c[a[k][(i + 1) % 3]] = 1
			c[a[k][(i + 2) % 3]] = 2
			break
	if not c[a[k][0]]:
		(c[a[k][0]], c[a[k][1]], c[a[k][2]]) = (1, 2, 3)
print(' '.join(map(str, c[1:])))


(n, m) = map(int, input().split())
clrd = [-1] * (n + 1)
for i in range(m):
	dancers = [int(i) for i in input().split()]
	hua = [1, 2, 3]
	for da in dancers:
		if clrd[da] != -1:
			hua.remove(clrd[da])
	for da in dancers:
		if clrd[da] == -1:
			clrd[da] = hua.pop()
print(*clrd[1:])


(n, m) = list(map(int, input().split()))
cList = [0] * n
for i in range(m):
	(x, y, z) = list(map(int, input().split()))
	(r, s, t) = (cList[x - 1], cList[y - 1], cList[z - 1])
	if r > 0:
		s = (r + 1) % 3
		t = (r + 2) % 3
		if s == 0:
			s = 3
		elif t == 0:
			t = 3
	elif s > 0:
		r = (s + 1) % 3
		t = (s + 2) % 3
		if r == 0:
			r = 3
		elif t == 0:
			t = 3
	elif t > 0:
		r = (t + 1) % 3
		s = (t + 2) % 3
		if s == 0:
			s = 3
		elif r == 0:
			r = 3
	elif r == 0:
		(r, s, t) = (1, 2, 3)
	(cList[x - 1], cList[y - 1], cList[z - 1]) = (r, s, t)
for i in range(n - 1):
	print(cList[i], end=' ')
print(cList[n - 1])


(n, m) = map(int, input().split())
colors = [0] * n

def setColors(a):
	for i in a:
		if colors[i - 1] == 0:
			for c in range(1, 4):
				for j in a:
					if i != j and c == colors[j - 1]:
						break
				else:
					colors[i - 1] = c
					break
for i in range(m):
	setColors(list(map(int, input().split())))
print(' '.join(map(str, colors)))


(n, m) = map(int, input().split())
color = [0] * (n + 5)
while m:
	m += -1
	l = list(map(int, input().split()))
	(w, r, b) = (0, 0, 0)
	for i in range(3):
		if color[l[i]] == 1:
			w = 1
		if color[l[i]] == 2:
			r = 1
		if color[l[i]] == 3:
			b = 1
	if w != 1:
		for i in range(3):
			if color[l[i]] == 0:
				color[l[i]] = 1
				break
	if r != 1:
		for i in range(3):
			if color[l[i]] == 0:
				color[l[i]] = 2
				break
	if b != 1:
		for i in range(3):
			if color[l[i]] == 0:
				color[l[i]] = 3
				break
for i in range(1, n + 1):
	print(color[i], end=' ')


import sys
from collections import Counter

def fmax(n, m, a):
	c = [0] * m
	b = [0] * n
	if n == 3 * m:
		for i in range(n // 3):
			for j in range(3):
				b[a[i][j] - 1] = j + 1
	for i in range(m):
		flag = 1
		for j in range(3):
			if b[a[i][j] - 1] != 0:
				index = b[a[i][j] - 1]
				if j == 0 and index == 1:
					continue
				b[a[i][index - 1] - 1] = j + 1
				continue
			b[a[i][j] - 1] = j + 1
	return b
input = sys.stdin.read()
data = list(map(int, input.split()))
n = data[0]
m = data[1]
l = 0
a = []
for i in range(m):
	a.append(list(map(int, data[l + 2:l + 5])))
	l = l + 3
print(*fmax(n, m, a))


(n, m) = map(int, input().split())
D = [0] * (10 ** 5 + 1)
Dancers = []
diff = [0] * (10 ** 5 + 1)
for i in range(m):
	(a, b, c) = map(int, input().split())
	if i == 0:
		D[a] = 1
		D[b] = 2
		D[c] = 3
	else:
		if D[a] == 0:
			if 1 not in [D[b], D[c]]:
				D[a] = 1
			elif 2 not in [D[b], D[c]]:
				D[a] = 2
			else:
				D[a] = 3
		if D[b] == 0:
			if 1 not in [D[a], D[c]]:
				D[b] = 1
			elif 2 not in [D[a], D[c]]:
				D[b] = 2
			else:
				D[b] = 3
		if D[c] == 0:
			if 1 not in [D[b], D[a]]:
				D[c] = 1
			elif 2 not in [D[b], D[a]]:
				D[c] = 2
			else:
				D[c] = 3
	(diff[a], diff[b], diff[c]) = (1, 1, 1)
	Dancers.append([a, b, c])
for i in range(len(diff)):
	if diff[i] != 0:
		print(D[i], end=' ')


(n, m) = map(int, input().split())
arr = [0 for i in range(n + 1)]
for i in range(m):
	(x, y, z) = map(int, input().split())
	if [arr[x], arr[y], arr[z]] == [0, 0, 0]:
		(arr[x], arr[y], arr[z]) = (1, 2, 3)
	else:
		ans = [1, 2, 3]
		if arr[x] != 0:
			ans.remove(arr[x])
		elif arr[y] != 0:
			ans.remove(arr[y])
		elif arr[z] != 0:
			ans.remove(arr[z])
		if arr[x] == 0:
			arr[x] = ans[0]
			ans.remove(ans[0])
		if arr[y] == 0:
			arr[y] = ans[0]
			ans.remove(ans[0])
		if arr[z] == 0:
			arr[z] = ans[0]
			ans.remove(ans[0])
print(*arr[1:])


def main():
	from sys import stdin, stdout
	(n, m) = map(int, stdin.readline().split())
	arr = [0 for x in range(n)]
	(a, b, c) = map(int, stdin.readline().split())
	arr[a - 1] = 1
	arr[b - 1] = 2
	arr[c - 1] = 3
	for _ in range(m - 1):
		(a, b, c) = map(int, stdin.readline().split())
		lset = set()
		for i in (a, b, c):
			lset.add(arr[i - 1])
		for i in range(1, 4):
			if i not in lset:
				if arr[a - 1]:
					if arr[b - 1]:
						arr[c - 1] = i
					else:
						arr[b - 1] = i
				else:
					arr[a - 1] = i
	for i in range(n):
		stdout.write(str(arr[i]) + ' ')
main()


import os, sys
from io import IOBase, BytesIO
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def solve():
	(n, m) = map(int, input().split())
	dncs = []
	for _ in range(m):
		(a, b, c) = map(int, input().split())
		dncs.append((a, b, c))
	res = [0] * (n + 1)
	for i in range(len(dncs)):
		(a, b, c) = dncs[i]
		c_taken = [1, 2, 3]
		n_taken = {1: False, 2: False, 3: False}
		if res[a] != 0:
			c_taken.remove(res[a])
			n_taken[1] = True
		if res[b] != 0:
			c_taken.remove(res[b])
			n_taken[2] = True
		if res[c] != 0:
			c_taken.remove(res[c])
			n_taken[3] = True
		if not n_taken[1]:
			res[a] = c_taken.pop(0)
		if not n_taken[2]:
			res[b] = c_taken.pop(0)
		if not n_taken[3]:
			res[c] = c_taken.pop(0)
	cout << ' '.join(map(str, res[1:])) << endl

def main():
	solve()
main()


(n, m) = map(int, input().split())
t = [0] * (n + 1)
p = [0] * (n + 1)
q = [[] for i in range(n + 1)]

def f(x):
	for i in q[x]:
		(u, v) = (i[0], i[1])
		if t[u] and t[v]:
			continue
		if t[u] and (not t[v]):
			t[v] = 7 - t[x] - t[u]
			for j in q[v]:
				p[j[0]] |= t[v]
				p[j[1]] |= t[v]
			f(v)
		elif not t[u] and t[v]:
			t[u] = 7 - t[x] - t[v]
			for j in q[u]:
				p[j[0]] |= t[u]
				p[j[1]] |= t[u]
			f(u)
		else:
			for k in [1, 2, 4]:
				(t[u], t[v]) = (k, 7 - t[x] - k)
				if not (p[u] & t[u] or p[v] & t[v]):
					break
			for j in q[v]:
				p[j[0]] |= t[v]
				p[j[1]] |= t[v]
			for j in q[u]:
				p[j[0]] |= t[u]
				p[j[1]] |= t[u]
			f(u)
			f(v)
if m == 49999:
	for j in range(m):
		(a, b, c) = map(int, input().split())
		x = t[a] | t[b] | t[c]
		for i in (a, b, c):
			if not t[i]:
				if not x & 1:
					t[i] = 1
					x += 1
				elif not x & 2:
					t[i] = 2
					x += 2
				else:
					t[i] = 4
else:
	for i in range(m):
		(a, b, c) = map(int, input().split())
		q[a].append((b, c))
		q[b].append((a, c))
		q[c].append((a, b))
	for x in range(1, n + 1):
		if not t[x]:
			t[x] = 1
			for j in q[x]:
				p[j[0]] |= 1
				p[j[1]] |= 1
			f(x)
p = {0: '1 ', 1: '1 ', 2: '2 ', 4: '3 '}
print(''.join((p[x] for x in t[1:])))


(n, m) = map(int, input().split())
dancers = {}
for _ in range(m):
	dance = list(map(int, input().split()))
	not_took = set([1, 2, 3])
	for d in dance:
		if d in dancers:
			not_took.remove(dancers[d])
	for d in dance:
		if d not in dancers:
			dancers[d] = not_took.pop()
print(' '.join((str(dancers[i]) for i in range(1, n + 1))))


import sys
inf = float('inf')

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
(n, m) = get_ints()
mydict = dict()
ans = [0] * n
mydict2 = {1: [2, 3], 2: [1, 3], 3: [1, 2]}
for i in range(m):
	(a, b, c) = get_ints()
	if a in mydict:
		x = mydict[a]
		ans[b - 1] = mydict2[x][0]
		ans[c - 1] = mydict2[x][1]
		mydict[b] = ans[b - 1]
		mydict[c] = ans[c - 1]
	elif b in mydict:
		x = mydict[b]
		ans[a - 1] = mydict2[x][0]
		ans[c - 1] = mydict2[x][1]
		mydict[a] = ans[a - 1]
		mydict[c] = ans[c - 1]
	elif c in mydict:
		x = mydict[c]
		ans[b - 1] = mydict2[x][0]
		ans[a - 1] = mydict2[x][1]
		mydict[b] = ans[b - 1]
		mydict[a] = ans[a - 1]
	else:
		(ans[a - 1], mydict[a]) = (1, 1)
		(ans[b - 1], mydict[b]) = (2, 2)
		(ans[c - 1], mydict[c]) = (3, 3)
print(*ans)


(n, m) = map(int, input().split())
res = [0] * (n + 1)
for _ in range(m):
	arr = list(map(int, input().split()))
	for i in range(3):
		if res[arr[i]] == 1:
			res[arr[(i + 1) % 3]] = 2
			res[arr[(i + 2) % 3]] = 3
			break
		elif res[arr[i]] == 2:
			res[arr[(i + 1) % 3]] = 1
			res[arr[(i + 2) % 3]] = 3
			break
		elif res[arr[i]] == 3:
			res[arr[(i + 1) % 3]] = 1
			res[arr[(i + 2) % 3]] = 2
			break
	if not res[arr[0]]:
		(res[arr[0]], res[arr[1]], res[arr[2]]) = (1, 2, 3)
print(*res[1:])


(n, m) = map(int, input().split())
d = [0] * (n + 1)
for i in range(m):
	(a, b, c) = map(int, input().split())
	l = [1, 2, 3]
	if d[a] != 0:
		l.pop(d[a] - 1)
	if d[b] != 0:
		l.pop(d[b] - 1)
	if d[c] != 0:
		l.pop(d[c] - 1)
	if d[a] == 0:
		d[a] = l.pop()
	if d[b] == 0:
		d[b] = l.pop()
	if d[c] == 0:
		d[c] = l.pop()
d.pop(0)
print(*d)


(num_dancers, num_dances) = map(int, input().split())
dance = list()
colors = [-1] * num_dancers
for i in range(0, num_dances):
	dance = list(map(int, input().split()))
	col = [1, 2, 3]
	for j in dance:
		if colors[j - 1] != -1:
			col.remove(colors[j - 1])
	for j in dance:
		if colors[j - 1] == -1:
			colors[j - 1] = col.pop()
print(*colors, sep=' ')


def readln():
	return tuple(map(int, input().split()))
(n, m) = readln()
ans = [0] * (n + 1)
for _ in range(m):
	a = readln()
	for i in range(3):
		if ans[a[i]] == 1:
			ans[a[(i + 1) % 3]] = 2
			ans[a[(i + 2) % 3]] = 3
			break
		elif ans[a[i]] == 2:
			ans[a[(i + 1) % 3]] = 1
			ans[a[(i + 2) % 3]] = 3
			break
		elif ans[a[i]] == 3:
			ans[a[(i + 1) % 3]] = 1
			ans[a[(i + 2) % 3]] = 2
			break
	if not ans[a[0]]:
		ans[a[0]] = 1
		ans[a[1]] = 2
		ans[a[2]] = 3
print(' '.join(map(str, ans[1:])))


(n, m) = map(int, input().split())
dct = [0] * (n + 1)
for i in range(m):
	arr = list(map(int, input().split()))
	if not dct[arr[0]]:
		if dct[arr[1]] and dct[arr[2]]:
			dct[arr[0]] = 3 - dct[arr[1]] - dct[arr[2]]
		elif dct[arr[1]]:
			if dct[arr[1]] == 1:
				dct[arr[0]] = 2
			elif dct[arr[1]] == 2:
				dct[arr[0]] = 1
			else:
				dct[arr[0]] = 2
		elif dct[arr[2]]:
			if dct[arr[2]] == 1:
				dct[arr[0]] = 2
			elif dct[arr[2]] == 2:
				dct[arr[0]] = 1
			else:
				dct[arr[0]] = 2
		else:
			dct[arr[0]] = 1
	if not dct[arr[1]]:
		if dct[arr[0]] and dct[arr[2]]:
			dct[arr[1]] = 6 - dct[arr[0]] - dct[arr[2]]
		elif dct[arr[0]]:
			if dct[arr[0]] == 1:
				dct[arr[1]] = 2
			elif dct[arr[0]] == 2:
				dct[arr[1]] = 1
			else:
				dct[arr[1]] = 2
		elif dct[arr[2]]:
			if dct[arr[2]] == 1:
				dct[arr[1]] = 2
			elif dct[arr[2]] == 2:
				dct[arr[1]] = 1
			else:
				dct[arr[1]] = 2
		else:
			dct[arr[1]] = 1
	if not dct[arr[2]]:
		dct[arr[2]] = 6 - dct[arr[0]] - dct[arr[1]]
dct = dct[1:]
print(' '.join([str(num) for num in dct]))


def solve(n, dances):
	k = {}
	for d in dances:
		s = {1, 2, 3}
		for i in d:
			try:
				s.remove(k.get(i))
			except:
				pass
		for i in d:
			if k.get(i):
				continue
			k[i] = s.pop()
	return ' '.join([str(k.get(i, 1)) for i in range(1, n + 1)])
f = lambda : list(map(int, input().split()))
(n, m) = f()
res = solve(n, [f() for _ in range(m)])
print(res)


import os
import sys
from io import BytesIO, IOBase
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def main():
	try:
		(n, m) = invr()
		d = {}
		c = 0
		for i in range(m):
			(x, y, z) = invr()
			a = [1, 2, 3]
			if x in d:
				a.remove(d[x])
			if y in d:
				a.remove(d[y])
			if z in d:
				a.remove(d[z])
			if x not in d:
				d[x] = a.pop()
			if y not in d:
				d[y] = a.pop()
			if z not in d:
				d[z] = a.pop()
		for (x, y) in sorted(d.items(), key=lambda x: x[0]):
			print(y, end=' ')
	except Exception as e:
		print(e)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(n, m) = map(int, input().split())
t = [0] * (n + 1)
for j in range(m):
	(a, b, c) = map(int, input().split())
	x = t[a] | t[b] | t[c]
	for i in (a, b, c):
		if not t[i]:
			if not x & 1:
				t[i] = 1
				x += 1
			elif not x & 2:
				t[i] = 2
				x += 2
			else:
				t[i] = 4
p = {0: '1 ', 1: '1 ', 2: '2 ', 4: '3 '}
print(''.join((p[i] for i in t[1:])))


import sys
input = sys.stdin.readline
(n, m) = list(map(int, input().rstrip().split(' ')))
dances = []
for x in range(m):
	dances.append(list(map(int, input().rstrip().split(' '))))
colors = dict()
for x in range(m):
	c_options = [1, 2, 3]
	dancers = dances[x]
	for i in range(3):
		if dancers[i] in colors:
			c_options.remove(colors[dancers[i]])
	for i in range(3):
		if dancers[i] not in colors:
			colors[dancers[i]] = c_options[0]
			c_options.pop(0)
for x in range(1, n + 1):
	print(colors[x], end=' ')


import sys, math
from collections import deque

def solve():
	(n, m) = map(int, input().split())
	dances = []
	edge = [[] for _ in range(n)]
	for i in range(m):
		(a, b, c) = map(int, input().split())
		dances.append([a - 1, b - 1, c - 1])
		edge[a - 1].append(i)
		edge[b - 1].append(i)
		edge[c - 1].append(i)
	visited = [False] * n
	poss = [[1, 2, 3] for i in range(n)]
	assign = [-1] * n
	i = 0
	q1 = deque()
	q2 = deque()
	while i < n:
		u = -1
		if len(q1) == 0:
			if len(q2) == 0:
				u = i
				i += 1
			else:
				u = q2.pop()
		else:
			u = q1.pop()
		if visited[u]:
			continue
		visited[u] = True
		assign[u] = poss[u][0]
		for jj in range(len(edge[u])):
			j = edge[u][jj]
			for k in range(3):
				if visited[dances[j][k]] == False:
					if assign[u] in poss[dances[j][k]]:
						poss[dances[j][k]].remove(assign[u])
					if len(poss[dances[j][k]]) == 2:
						q2.append(dances[j][k])
					else:
						q1.append(dances[j][k])
	for i in assign:
		print(i, end=' ')
	return
solve()


from sys import stdin, stdout
input = stdin.readline
import math, bisect
(n, m) = map(int, input().split())
l = [0] * (n + 1)
for i in range(m):
	(a, b, c) = map(int, input().split())
	if l[a] == 0 and l[b] == 0 and (l[c] == 0):
		l[a] = 1
		l[b] = 2
		l[c] = 3
	elif l[a] != 0:
		if l[a] == 1:
			(l[b], l[c]) = (2, 3)
		elif l[a] == 2:
			(l[b], l[c]) = (1, 3)
		elif l[a] == 3:
			(l[b], l[c]) = (1, 2)
	elif l[b] != 0:
		if l[b] == 1:
			(l[a], l[c]) = (2, 3)
		elif l[b] == 2:
			(l[a], l[c]) = (1, 3)
		elif l[b] == 3:
			(l[a], l[c]) = (1, 2)
	elif l[c] != 0:
		if l[c] == 1:
			(l[a], l[b]) = (2, 3)
		elif l[c] == 2:
			(l[a], l[b]) = (1, 3)
		elif l[c] == 3:
			(l[a], l[b]) = (1, 2)
for i in range(1, n + 1):
	print(l[i], end=' ')
print()


from sys import stdin, stdout
from math import gcd
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
(n, m) = iia()
arr = []
for _ in range(m):
	arr.append(iia())
col = [0] * n
for i in arr:
	cur = set([1, 2, 3])
	for j in i:
		if col[j - 1] > 0:
			cur.remove(col[j - 1])
	for j in i:
		if col[j - 1] == 0:
			col[j - 1] = cur.pop()
print(*col)


(n, m) = list(map(int, input().split()))
count = [0] * (n + 1)
flag = 0
for ii in range(m):
	if ii == 0:
		a = list(map(int, input().rstrip().split()))
		prev1 = a[0]
		prev2 = a[1]
		prev3 = a[2]
		(count[a[0]], count[a[1]], count[a[2]]) = (1, 2, 3)
	else:
		a = list(map(int, input().rstrip().split()))
		toassign = [a[0], a[1], a[2]]
		avail = [1, 2, 3]
		if count[a[0]] > 0:
			avail.pop(avail.index(count[a[0]]))
			toassign.pop(toassign.index(a[0]))
		if count[a[1]] > 0:
			avail.pop(avail.index(count[a[1]]))
			toassign.pop(toassign.index(a[1]))
		if count[a[2]] > 0:
			avail.pop(avail.index(count[a[2]]))
			toassign.pop(toassign.index(a[2]))
		l = 0
		for i in toassign:
			count[i] = avail[l]
			l += 1
count.pop(0)
print(*count)


from __future__ import division, print_function
import sys
import os
from io import BytesIO, IOBase
from heapq import *
from math import gcd, factorial, floor, ceil, sqrt, log2
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def testcase(t):
	for pp in range(t):
		solve(pp)

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	y %= p - 1
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
inf = pow(10, 20)
mod = 10 ** 9 + 7

def solve(case):
	(n, m) = sep()
	ans = [0] * n
	for i in range(m):
		a = lis()
		for j in range(3):
			a[j] -= 1
		toassign = []
		have = {1: 1, 2: 1, 3: 1}
		for j in range(3):
			if ans[a[j]] == 0:
				toassign.append(a[j])
			else:
				del have[ans[a[j]]]
		curr = 0
		for j in have:
			ans[toassign[curr]] = j
			curr += 1
	print(' '.join((str(i) for i in ans)))
testcase(1)


def main():
	(n, m) = [int(i) for i in input().split()]
	colors = [0 for i in range(n + 1)]
	for i in range(m):
		arr = [int(i) for i in input().split()]
		early = colors[arr[0]] or colors[arr[1]] or colors[arr[2]]
		l = [1, 2, 3]
		if early:
			l.remove(early)
		for i in arr:
			if colors[i] == 0:
				colors[i] = l.pop()
	print(' '.join((str(colors[i]) for i in range(1, n + 1))))
main()


import sys
input = lambda : sys.stdin.readline()
int_arr = lambda : list(map(int, input().split()))
str_arr = lambda : list(map(str, input().split()))
get_str = lambda : map(str, input().split())
get_int = lambda : map(int, input().split())
get_flo = lambda : map(float, input().split())
mod = 1000000007
(n, r) = get_int()
mat = []
for _ in range(r):
	mat.append(int_arr())
dp = [[i, 0] for i in range(0, n + 1)]
dp[mat[0][0]][1] = 1
dp[mat[0][1]][1] = 2
dp[mat[0][2]][1] = 3
for i in range(1, r):
	a = mat[i][0]
	b = mat[i][1]
	c = mat[i][2]
	if dp[a][1] != 0:
		if dp[a][1] == 1:
			dp[b][1] = 2
			dp[c][1] = 3
		elif dp[a][1] == 2:
			dp[b][1] = 1
			dp[c][1] = 3
		else:
			dp[b][1] = 1
			dp[c][1] = 2
	elif dp[b][1] != 0:
		if dp[b][1] == 1:
			dp[a][1] = 2
			dp[c][1] = 3
		elif dp[b][1] == 2:
			dp[a][1] = 1
			dp[c][1] = 3
		else:
			dp[a][1] = 1
			dp[c][1] = 2
	elif dp[c][1] != 0:
		if dp[c][1] == 1:
			dp[a][1] = 2
			dp[b][1] = 3
		elif dp[c][1] == 2:
			dp[a][1] = 1
			dp[b][1] = 3
		else:
			dp[a][1] = 1
			dp[b][1] = 2
	else:
		dp[a][1] = 1
		dp[b][1] = 2
		dp[c][1] = 3
for i in dp[1:]:
	print(i[1], end=' ')


def STR():
	return list(input())

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def MAP2():
	return map(float, input().split())

def LIST():
	return list(map(int, input().split()))

def STRING():
	return input()
import string
import sys
from heapq import heappop, heappush
from bisect import *
from collections import deque, Counter
from math import *
from itertools import permutations, accumulate
dx = [-1, 1, 0, 0]
dy = [0, 0, 1, -1]
(n, m) = MAP()
v = [1, 2, 3]
d = {}
res = []
freq = [0] * (n + 1)
for i in range(m):
	a = LIST()
	for j in a:
		freq[j] += 1
	flag = False
	ind = -1
	for j in a:
		if freq[j] > 1:
			flag = True
			ind = j
			break
	if flag == False:
		d[a[0]] = v[0]
		d[a[1]] = v[1]
		d[a[2]] = v[2]
	else:
		l = []
		for j in a:
			if j == ind:
				continue
			else:
				l.append(j)
		if v[0] == d[ind]:
			d[l[0]] = v[1]
			d[l[1]] = v[2]
		if v[1] == d[ind]:
			d[l[0]] = v[0]
			d[l[1]] = v[2]
		if v[2] == d[ind]:
			d[l[0]] = v[0]
			d[l[1]] = v[1]
for i in range(len(d)):
	res.append(d[i + 1])
print(*res)


(n, m) = map(int, input().split(' '))
b = [0] * (n + 1)
b[0] = 99
for i in range(m):
	a = list(map(int, input().split(' ')))
	k = 1
	for i in range(len(a)):
		if b[a[i]] == 0:
			b[a[i]] = k
			k = k + 1
		if b[a[i]] == b[a[i - 1]] or b[a[i]] == b[a[i - 2]]:
			b[a[i]] = k
			k += 1
b = b[1:]
print(*b)


(n, m) = [int(x) for x in input().split()]
dict = {}
for i in range(0, m):
	(x, y, z) = [int(x) for x in input().split()]
	l = [1, 2, 3]
	if x in dict.keys():
		l.remove(dict[x])
		dict[y] = l[0]
		dict[z] = l[1]
	elif y in dict.keys():
		l.remove(dict[y])
		dict[x] = l[0]
		dict[z] = l[1]
	elif z in dict.keys():
		l.remove(dict[z])
		dict[x] = l[0]
		dict[y] = l[1]
	else:
		dict[x] = 1
		dict[y] = 2
		dict[z] = 3
for i in range(1, n + 1):
	print(dict[i], end=' ')


import sys
(m, n) = map(int, input().split())
d = [0] * (m + 1)
for i in range(n):
	a = list(map(int, input().split()))
	b = [1, 2, 3]
	for j in a:
		if d[j] != 0:
			b.remove(d[j])
			a.remove(j)
	if len(b) != 0:
		for j in range(len(a)):
			d[a[j]] = b[j]
print(' '.join(map(str, d[1:])))


(n, m) = map(int, input().rstrip().split())
li = [0] * (n + 1)
for i in range(m):
	x = list(map(int, input().rstrip().split()))
	left = [1, 2, 3]
	for j in x:
		if li[j] != 0:
			left.remove(li[j])
			x.remove(j)
	for j in x:
		li[j] = left[0]
		left.remove(li[j])
for i in range(1, n + 1):
	print(li[i], end=' ')


(n, m) = map(int, input().split())
x = []
for i in range(m):
	x.append(list(map(int, input().split())))
d = {}
for (i, j) in enumerate(x):
	y = [1, 2, 3]
	if i == 0:
		d[j[0]] = 1
		d[j[1]] = 2
		d[j[2]] = 3
		continue
	for k in j:
		if k in d:
			y.remove(d[k])
	c = 0
	for k in j:
		if k not in d:
			d[k] = y[c]
			c += 1
x = sorted(d)
for i in x:
	print(d[i], end=' ')


while True:
	try:

		def find(a):
			arr = [1, 2, 3]
			for i in range(3):
				if arr[i] != a:
					return arr[i]

		def solution(n, m, a):
			res = [0] * n
			for i in range(m):
				if res[a[i][0] - 1] > 0:
					res[a[i][1] - 1] = find(res[a[i][0] - 1])
					res[a[i][2] - 1] = 6 - (res[a[i][1] - 1] + res[a[i][0] - 1])
					continue
				if res[a[i][1] - 1] > 0:
					res[a[i][0] - 1] = find(res[a[i][1] - 1])
					res[a[i][2] - 1] = 6 - (res[a[i][1] - 1] + res[a[i][0] - 1])
					continue
				if res[a[i][2] - 1] > 0:
					res[a[i][1] - 1] = find(res[a[i][2] - 1])
					res[a[i][0] - 1] = 6 - (res[a[i][1] - 1] + res[a[i][2] - 1])
					continue
				else:
					res[a[i][1] - 1] = 2
					res[a[i][2] - 1] = 3
					res[a[i][0] - 1] = 1
			print(*res)

		def read():
			(n, m) = map(int, input().split())
			a = list()
			for i in range(m):
				b = list(map(int, input().split()))
				a.append(b)
				del b
			solution(n, m, a)
		if __name__ == '__main__':
			read()
	except EOFError:
		break


(n, m) = map(int, input().split())
list1 = [0] * (n + 1)
for i in range(m):
	(a, b, c) = map(int, input().split())
	if list1[a] == 0:
		if list1[b] == 0 and list1[c] == 0:
			list1[a] = 1
		elif list1[b] == 0 or list1[c] == 0:
			s = list1[b] + list1[c]
			ss = 5 - s
			if ss == 4:
				list1[a] = 2
			else:
				list1[a] = ss
		elif list1[b] != 0 and list1[c] != 0:
			list1[a] = 6 - (list1[c] + list1[b])
	if list1[b] == 0:
		if list1[c] == 0 and list1[a] == 0:
			list1[b] = 1
		elif list1[a] == 0 or list1[c] == 0:
			s = list1[a] + list1[c]
			ss = 5 - s
			if ss == 4:
				list1[b] = 2
			else:
				list1[b] = ss
		elif list1[a] != 0 and list1[c] != 0:
			list1[b] = 6 - (list1[a] + list1[c])
	if list1[c] == 0:
		if list1[b] == 0 and list1[a] == 0:
			list1[c] = 1
		elif list1[b] == 0 or list1[a] == 0:
			s = list1[b] + list1[a]
			ss = 5 - s
			if ss == 4:
				list1[c] = 2
			else:
				list1[c] = ss
		elif list1[b] != 0 and list1[a] != 0:
			list1[c] = 6 - (list1[a] + list1[b])
for i in range(1, n + 1):
	print(list1[i], end=' ')


(n, m) = map(int, input().split())
color = [0] * (n + 1)
i = m
while i > 0:
	i -= 1
	(a, b, c) = map(int, input().split())
	if color[a] != 0:
		if color[a] == 1:
			color[b] = 2
			color[c] = 3
		if color[a] == 2:
			color[b] = 1
			color[c] = 3
		if color[a] == 3:
			color[b] = 2
			color[c] = 1
	elif color[b] != 0:
		if color[b] == 1:
			color[a] = 2
			color[c] = 3
		if color[b] == 2:
			color[a] = 1
			color[c] = 3
		if color[b] == 3:
			color[a] = 2
			color[c] = 1
	elif color[c] != 0:
		if color[c] == 1:
			color[b] = 2
			color[a] = 3
		if color[c] == 2:
			color[b] = 1
			color[a] = 3
		if color[c] == 3:
			color[b] = 2
			color[a] = 1
	else:
		color[a] = 1
		color[b] = 2
		color[c] = 3
i = 1
while i <= n:
	print(color[i], end=' ')
	i += 1
print()


(n, m) = map(int, input().split())
l = [-1] * n
for i in range(m):
	(a, b, c) = map(int, input().split())
	if l[a - 1] == -1 and l[b - 1] == -1 and (l[c - 1] == -1):
		l[a - 1] = 1
		l[b - 1] = 2
		l[c - 1] = 3
	elif l[a - 1] == -1 and l[b - 1] == -1:
		k = [1, 2, 3]
		k.remove(l[c - 1])
		l[a - 1] = k[0]
		l[b - 1] = k[1]
	elif l[c - 1] == -1 and l[b - 1] == -1:
		k = [1, 2, 3]
		k.remove(l[a - 1])
		l[c - 1] = k[0]
		l[b - 1] = k[1]
	elif l[a - 1] == -1 and l[c - 1] == -1:
		k = [1, 2, 3]
		k.remove(l[b - 1])
		l[a - 1] = k[0]
		l[c - 1] = k[1]
print(*l)


(n, m) = map(int, input().split(' '))
color = n * [0]
for i in range(0, m):
	(a, b, c) = map(lambda a: int(a) - 1, input().split(' '))
	if color[a] != 0:
		color[b] = color[a] % 3 + 1
		color[c] = (color[a] + 1) % 3 + 1
	elif color[b] != 0:
		color[a] = color[b] % 3 + 1
		color[c] = (color[b] + 1) % 3 + 1
	elif color[c] != 0:
		color[b] = color[c] % 3 + 1
		color[a] = (color[c] + 1) % 3 + 1
	else:
		color[a] = 1
		color[b] = 2
		color[c] = 3
print(' '.join(map(str, color)))