N, M = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(M)]

keta = [0,0,0]
DP = [0,0,0]

for i in sc:
  s = i[0]
  c = i[1]
  if DP[-1*N+s-1] == 0 or (DP[-1*N+s-1] == 1 and keta[-1*N+s-1] == c):
    keta[-1*N+s-1] = c
    DP[-1*N+s-1] = 1
  else:
    DP[-1*N+s-1] = -1
    
if keta[-1*N] == 0:
  DP[-1*N] = -1
  
if -1 in DP:
  print(-1)
else:
  ans = ''
  for i in keta:
    ans += str(i)
  print(int(ans[3-N:]))
#print(DP)