n,m = map(int, input().split())
s=[]
for i in range(m):
  s.append(list(map(int, input().split())))

for i in range(1000):
  for si in s:
    if len(str(i)) < si[0]:
      break
    if str(i)[si[0]-1] != str(si[1]):
      break
  else:
    print(i)
    break
else:
  print(-1)
