N,M = map(int,input().split())
A = ['a']*N
for _ in range(M):
  s,c = map(int,input().split())
  if A[s-1] == 'a' or A[s-1] == str(c):
    A[s-1] = str(c)
  else:
    print(-1)
    exit()
if A[0] == '0':
  print(-1)
  exit()
elif A[0] == 'a':
  A[0] == '1'
Ans = ''.join(A)
Ans = Ans.replace('a','0')

print(int(Ans))