n, m = map(int, input().split())

ans = list(' '*n)

for i in range(m):
  a, b = map(int, input().split())
  
  if a==1 and b ==0:
    print(-1)
    exit()
  if ans[a-1] != ' ' and ans[a-1] != str(b):
    print(-1)
    exit()
    
  ans[a-1] = str(b)


if ans[0] == ' ':
  ans[0] = '1'
ans = ''.join(ans)

print(int(ans.replace(' ', '0')))
