import sys
n,m = map(int,input().split())
ans = []
for i in range(n):
  ans.append([])
for i in range(m):
  s,c = map(int,input().split())
  if(s==1)and(c==0):
    print(-1)
    sys.exit()
    None
  else:
    ans[s-1].append(c)
ansn = 0
if(len(ans[0])==0):
  ansn += 10**(n-1)
elif(len(ans[0])==1):
  ansn += ans[0][0]*10**(n-1)
else:
   print(-1)
   sys.exit()
for i in range(1,m):
  if(len(ans[i])==0):
    ansn += 0
  elif(len(ans[i])==1):
    ansn += min(ans[i][0])*10**(n-i-1)
  else:
     print(-1)
     sys.exit()
print(ansn)

