n,m = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(m)]
ans = [0]*(n+1)
answer = 0
for i in range(m):
  dig = sc[i][0]
  if ans[dig] == 0 or ans[dig] == sc[i][1]:
    ans[dig] = sc[i][1]
  else:
    print("-1")
    exit()
for i in range(1,n+1):
  answer += ans[i]*10**(n-i)
if answer == 0 and n != 1:
  print("-1")
elif answer < 10**n:
  print("-1")
else:
  print(answer)
