n, m = map(int, input().split())
a = [-1] * n
for i in range(m):
  s, c = map(int, input().split())
  s -= 1
  if a[s] == -1 or a[s] == c:
    a[s] = c
  else:
    print(-1)
    exit(0)
for i in range(n):
  if a[i] == -1:
    a[i] = 0
ans = 0
a.reverse()
for i in range(n):
  ans += a[i] * 10 ** i
if len(str(ans)) == n:
  print(ans)
else:
  print(-1)