def mi():return map(int,input().split())
n,m=mi()
sc=[]
for i in range(m):
  s,c=mi()
  sc+=(s,c),
  
for i in range(0,999+1):
  h=str(i)
  if len(h)==n:
    if all([h[s-1]==str(c) for s,c in sc]):
      print(i)
      exit()
print(-1)    