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

if n==0:
  ans=[0]
  for s,c in SC:
    if ans[s-1]==0:
      ans[s-1]=c
    else:
      if ans[s-1]!=c:
        prin
        t(-1)
      exit()
else:
  ans=[0]*n
  ans[0]=1
  for s,c in SC:
    if ans[s-1]==0:
      ans[s-1]=c
    else:
      if ans[s-1]!=c:
        print(-1)
        exit()
  if ans[0]==0:
    ans[0]=1
    
print(*ans,sep='')