N, M = map(int, input().split())
A = [-2 for i in range(N)]
for i in range(M):
  c, n = map(int, input().split())
  if A[c-1] != -2 and A[c-1] != n:
    A[c-1] = -1
  elif A[c-1] != -1 or A[c-1] == n:
    A[c-1] = n
if -1 in A:
  print(-1)
else:
  if N == 1 and A[0] == -2:
    print(0)
  elif N != 1:
    if A[0] == -2:
      A[0] = 1
    for i in range(1, N):
      if A[i] == -2:
        A[i] = 0
    if A[0] != 0:
      for i in range(N):
        print(A[i], end = '')
      print()
    else:
      print(-1)