def MI():return map(int,input().split())

n,m=MI()
sc=[]
for _ in range(m):
  s,c=MI()
  sc+=(s-1,c),
  
for i in range(0,999):
  S=str(i)
  if len(S)==n:
    if all([S[s]==str(c) for s,c in sc]):
      print(i)
      exit()
print(-1)