N,M = map(int,(input().split()))

a = [-1]*N

for i in range(M):
  s,c = map(int,input().split())
  if a[s-1] == -1:
    a[s-1] = c
  elif a[s-1] != -1:
    if a[s-1] != c:
      print(-1)
      exit()
for i in range(len(a)):
  if a[i] == -1:
    a[i] = 0
if len(a) != 1 and a[0] == -1:
  a[0] = 1
elif len(a) != 1 and a[0] == 0:
  print(-1)
  exit()
print("".join(map(str,a)))
  