def run(inp):
  (N, M) = [int(v) for v in inp[0].split(' ')]
  valueMap = [10 for i in range(N)]
  is_success = True

  for i in range(M):
    (s, c) = [int(v) for v in inp[i + 1].split(' ')]
    s -= 1
    
    if (valueMap[s] != 10 and valueMap[s] != c):
      is_success = False
      break

    if (valueMap[s] > c and c != 0):
      valueMap[s] = c

  valueMap = list(map(lambda v: 0 if v == 10 else v, valueMap))

  if (not is_success or len(valueMap) != 1 and valueMap[0] == 0):
    return "-1"
  else:
    return "".join(map(str, valueMap))


vs = input()
(N, M) = [int(v) for v in vs.split(' ')]
inp = [input() for i in range(M)]
inp.insert(0, vs)
print(run(inp))