n,m=map(int,input().split())
SC=[]
for i in range(m):
  s,c=map(int,input().split())
  SC.append((s,c))
for i in range(1000):
  chk=0
  i=str(i)
  l=len(i)
  for s,c in SC:
    if s<=l and i[s-1]==str(c):
      chk+=1
  if chk==m and l==n:
    print(int(i))
    break
else:
  print(-1)


