N, M = map(int, input().split())
X = [list(map(int, input().split())) for i in range(M)]
ans = [0, 0, 0]

for j in range(M):
  if ans[X[j][0]+2-N] == X[j][1] or ans[X[j][0]+2-N] == 0:
    ans[X[j][0]+2-N] = X[j][1]
    
  else:
    ans = '-1'
    break

if N == 3 and ans[0] == 0:
  print('-1')
  
elif N ==2 and ans[1] == 0:
  print('-1')
  
else:
  ansstr = list(map(str, ans))
  ans = ''.join(ansstr)
  print(int(ans))