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 n==1 and ans[0]==0:
  print(0)
  exit()

if ans[0]==0:
  print(-1)
  exit()

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

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