N,M = map(int,input().split())
ans = ["0"]*N

for i in range(M):
  s,c = map(int,input().split())
  if ans[s-1] == "0" or ans[s-1] == str(c):
    ans[s-1] = str(c)
  else:
    ans = "-1"
    break

if ans[0] == 0 and N != 1:
  ans = "-1"

print(''.join(ans))