import itertools as iter import collections as coll import heapq as hq import bisect as bis from decimal import Decimal as dec from functools import cmp_to_key import math import sys #import pypyjit #pypyjit.set_param('max_unroll_recursion=-1') sys.setrecursionlimit(10 ** 6) inp = sys.stdin.readline input = lambda : inp().rstrip() getN = lambda : int(inp()) getNs = lambda : map(int, inp().split()) getList = lambda :list(map(int, inp().split())) getStrs = lambda n : [input() for _ in [0] * n] def yexit(): print("Yes"); exit(0) def nexit(): print("No"); exit(0) pi = 3.141592653589793 mod = 1000000007 MOD = 998244353 INF = 4611686018427387903 dx = [1, 0, -1, 0]; dy = [0, 1, 0, -1] """ Main Code """ n, m = getNs() lis = [getList() for _ in [0] * m] table = [[0] * 3 for _ in [0] * n] route = [[] for _ in [0] * n] for p, q, a, b in lis: p -= 1; q -= 1 a -= 1; b -= 1 table[p][a] = table[q][b] = 1 route[p].append((q, b)) route[q].append((p, a)) ans = [0] * n que = [] #print(table) for i in range(n): cnt = 0 for j in table[i]: cnt += j if(cnt != 1): continue que.append(i) visited = [0] * n while(que): i = que.pop() if(visited[i]): continue visited[i] = True for j in range(3): if not(table[i][j]): continue ans[i] = j + 1 break for ni, t in route[i]: if(visited[ni]): continue visited[ni] = True table[ni][t] = 0 cnt = 0 for j in table[ni]: cnt += j if(cnt > 1): continue que.append(ni) for i in range(n): if(ans[i] > 0): continue for j in table[ni]: cnt += j if(cnt > 1): print(-1) exit(0) ans[i] = 1 print(*ans)