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

for i in range(M):
  S,C = list(map(int,input().split()))
  if N != 1 and C == 0 and S == 1:
    print('-1')
    exit()
  if ans[S-1] == C:
    continue
  elif ans[S-1] != -1:
    print('-1')
    exit()
  ans[S-1] = C
  
for i in range(N):
  if ans[i] == -1:
    ans[i] = str(0)
  ans[i] = str(ans[i])

print("".join(ans))