n,m = map(int,input().split())
a = [-1 for i in range(n)]
ans = True
for i in range(m):
  s,c = map(int,input().split())
  s -= 1
  if (n != 1 and s == 0 and c == 0) or (a[s] != -1 and a[s] != c):
    ans = False
    print(-1)
    break
  else:
    a[s] = c
if ans:
  for i in range(n):
    if a[i] == -1:
      a[i] = 0
    a[i] = str(a[i])
  print("".join(a))
  