N, M = map(int, input().split())
ans = [-1]*N
reg = [list(map(int, input().split())) for _ in range(M)]
answer = True
for s, c in reg:
  if ans[s-1]!=-1 and ans[s-1]!=c:
    answer = False
    break
  else:
    ans[s-1]=c
if not answer:
  print(-1)
elif ans[0]==0 and N!=1:
  print(-1)
else:
  for i in range(N):
    if i==0 and ans[0]==-1:
      ans[0]=1
    elif ans[i]==-1:
      ans[i]=0
  print(int(''.join([str(i) for i in ans])))