N,M = map(int,input().split())
sc = [list(map(int,input().split())) for _ in range(M)]
i = 0

while len(str(i))<=N:
  k = 0
  if len(str(i))!=N:
    i += 1
    continue
  for el in sc:
    if str(i)[el[0]-1] == str(el[1]):
      k += 1
  if k == M:
    print(i)
    exit()
  i += 1
  
print(-1)