n,m = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(m)]
anslist = []
for i in range(10**n):
  for j in range(len(sc)):
    k = sc[j][0]
    if len(str(i)) != n or str(i)[k-1] != str(sc[j][1]):
      break
  else:
    anslist.append(i)
if anslist:
  print(anslist[0])
else:print(-1)
