N,M=map(int,input().split())
S=[]
C=[]
for i in range(M):
  s1,c1=[int(i) for i in input().split()]
  S.append(s1)
  C.append(c1)
for i in range(pow(10,N),pow(10,N+1)):
  i=str(i)
  for s,c in zip(S,C):
    if i[s]==c:
      print(i)
      exit()
else:
  print("-1")