N,M=map(int,input().split())
ANS=[1]*N
Q=[list(map(int,input().split())) for i in range(M)]
for i in range(M):
  Q[i][0]-=1
  Q[i][1]-=1
  if (not(1<=Q[i][2]<=3)) and (not(1<=Q[i][3]<=3)):
    print(-1)
    exit()
  if (not(1<=Q[i][2]<=3)):
    ANS[Q[i][1]]=Q[i][3]
  if (not(1<=Q[i][3]<=3)):
    ANS[Q[i][0]]=Q[i][2]
for i in range(M):
  if ANS[Q[i][0]]!=Q[i][2] and ANS[Q[i][1]]!=Q[i][3]:
    print(-1)
    exit()
print(*ANS)