a = input().split()
N=int(a[0])
M=int(a[1])
ans=[-1]*N
for i in range(M):
  s,c = map(int, input().split())
  if s==1 and c==0 and N!=1:
    print(-1)
    exit()
    break
  elif ans[s-1]==-1:
    ans[s-1]=c
  elif ans[s-1]==c:
    pass
  elif ans[s-1]!=c and ans[s-1]!=-1:
    print(-1)
    exit()
    break
else:
  if ans[0]==-1:
    ans[0]=1
  for j in range(1,N):
    if ans[j]==-1:
      ans[j]=0
res=map(str,ans)
res=''.join(res)
print(int(res))