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

for i in range(999):
  i=list(str(i))
  flag=True
  for s,c in SC:
    if s-1>=len(i): break
    if int(i[s-1])!=c: break
  else:
    if len(i)==n:
      print(*i,sep='')
      exit()
print(-1)
