n, m = list(map(int, input().split()))
ans = [0,0,0]
for i in range(m):
  s,c = list(map(int, input().split()))
  if ans[s-1] == c or ans[s-1] == 0:
    ans[s-1] = c
  else:
    print(-1)
    break
while ans[0] == 0 and len(ans) != 1:
  ans = ans[1:]
if len(ans) == n: 
  print(''.join([str(i) for i in ans]))
else:
  print(-1)