import sys int1 = lambda x: int(x) - 1 # input = lambda: sys.stdin.buffer.readline() input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) i1 = lambda: int1(input()) mi = lambda: map(int, input().split()) mi1 = lambda: map(int1, input().split()) li = lambda: list(mi()) li1 = lambda: list(mi1()) lli = lambda n: [li() for _ in range(n)] INF = float("inf") mod = int(1e9 + 7) # mod = 998244353 n, m = mi() ans = [-1] * n for _ in range(m): p, q, a, b = mi() p, q = p - 1, q - 1 if a == 1 or b == 1: continue if 1 <= a <= 3: if ans[p] != -1: print(-1) exit(0) else: ans[p] = a elif 1 <= b <= 3: if ans[q] != -1: print(-1) exit(0) else: ans[q] = b else: print(-1) exit(0) for i in range(n): if ans[i] == -1: ans[i] = 1 print(*ans)