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

ret = float('inf')
for i in range(10 ** (N - 1), 10 ** N) :
  i = str(i)
  for s, c in sc :
    if s > len(i) or int(i[s - 1]) != c :
      break
  else :
    ret = min(ret, int(i))
    
if ret == float('inf') :
  print(-1)
else :
  print(ret)