import sys
n,m=map(int,input().split())
ll = [list(map(int,input().split())) for _ in [0]*m]
s = '*'*n
for l in ll:
  if s[l[0]-1]!='*' and s[l[0]-1]!=str(l[1]):
    print(-1)
    sys.exit()
  s=s[:l[0]-1]+str(l[1])+s[l[0]:]
s=s.replace('*','0',3)
if s[0]=='0' and len(s) != 1:
  print(-1)
  sys.exit()
print(s)