import sys
N,M=map(int,input().split())
sc=[-1]*N
for _ in range(M):
  s,c=map(int,input().split())
  if sc[s-1]==-1:
    sc[s-1]=c
  elif sc[s-1]!=c:
    print("-1")
    sys.exit(0)
    
if sc[0]==-1 and N!=1:
  sc[0]=1
elif sc[0]==0 and N==1:
  print("0")
  sys.exit(0)
for i in range(1,N):
  if sc[i]==-1:
    sc[i]=0

for i in range(N):
  if sc[i]!=0:
    break
  else:
    if i==N-1:
      print("-1")
      sys.exit(0)
print((''.join(map(str, sc))))
