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