a = input().split()
N=int(a[0])
M=int(a[1])
ans=10**(N-1)
ans=list(str(ans))
ans = [int(i) for i in ans]
f1=False
f2=False

for i in range(M):
  s = list(map(int,input().split()))
  if s[0]==1 and s[1]==0:
    print(-1)
    break
  if s[0]!=1 and ans[s[0]-1] == 0 :
    if f1==False:
      ans[s[0]-1]=s[1]
      f1=True
    else:
      if s[0]!=0:
        print(-1)
        break
  elif s[0]==1 and ans[0]==1:
    if f2==False:
      ans[0]=s[1]
      f2=True
    else:
      if s[0]!=1:
        print(-1)
        break
  elif ans[s[0]-1]==s[1]:
    continue
  else:
    print(-1)
    break
else:
  res=0
  for i in range(N):
    res+=ans[i]*10**(N-1-i)
  print(res)
 