N, M = map(int, input().split())
lis = {}
for i in range(M):
  s, c = map(int, input().split())
  if s == 1 and c == 0:
    print(-1)
    exit()
  if s in lis:
    if lis[s] == c:
      continue
    else:
      print(-1)
      exit()
  else:
    lis[s] = c
for i in range(1, N+1):
  if not i in lis:
    lis[i] = 0
ans = ""
for i in range(1, N+1):
  ans += str(lis[i])
print(ans)