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

ans = [-1 for n in range(N)] 

isConflict = False

for m in range(M):
  s, c = list(map(int, input().split()))
  if(ans[s-1] != -1):
    if(ans[s-1] != c):
      isConflict = True
      break
  ans[s-1] = c
if(isConflict):
  print(-1)
else:
  if(N != 1 and ans[0] == -1 or ans[0] == 0):
    print(-1)
  else:
    p = []
    for s in ans:
        if(s == -1):
            p.append("0")
        else:
            p.append(str(s))
    print("".join(p))