n,m=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(m)]

ans=[-1]*n
for s,c in sc:
  s-=1

  if ans[s]!=-1 and ans[s]!=c:
    print(-1)
    exit()

  ans[s]=c

if ans[0]==0:
  print(-1)
  exit()
else:
  for i in range(len(ans)):
    if ans[i]==-1:
      ans[i]=0

ans=[str(i) for i in ans]
print(''.join(ans))