N, M = map(int, input().split())
a = []
for i in range(M):
  a.append(list(map(int, input().split())))
for i in range(M):
  if a[i][0] == 1 and a[i][1] == 0:
    print("-1")
    exit(0)
ans_A = [0]*(N)
ans_R = [0]*(N)
for i in range(M):
  ans_A[a[i][0]-1]=a[i][1]
for i in range(M):
  ans_R[a[M-1-i][0]-1] = a[M-1-i][1]
if ans_A != ans_R:
  print("-1")
elif ans_A[0] == 0:
  ans_A[0] == 1
  Ans = ''.join([str(n) for n in ans_A])
  print(Ans)
else:
  Ans = ''.join([str(n) for n in ans_A])
  print(Ans)