n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(m)]
# n桁
# m個の要求
# 左からs桁目はc

ans = [0]*n
check = 0

for i in range(0,m):
  if ans[a[i][0]-1] == 0 or ans[a[i][0]-1] == a[i][1]:
    ans[a[i][0]-1] = a[i][1]
  else:
    check += 1

ans = map(str, ans)
ans = "".join(map(str, ans))
ans = int("".join(map(str, ans)))

if check == 0 and len(str(ans)) == n:
  print(ans)
else:
  print(-1)