import sys
n,m=map(int,input().split())
sc = [list(map(int,input().split())) for i in range(m)]
for i in range(10**(n-1),10**n):
  for j in range(m):
    sti = str(i)
    if sti[sc[j][0]-1] != str(sc[j][1]):
      break
  else:
    print(i)
    sys.exit()
print(-1)