vs = input().split(' ')
N = int(vs[0])
M = int(vs[1])
valueMap = [10 for i in range(N)]

for i in range(M):
  vs = input().split(' ')
  t_i = int(vs[0]) - 1
  t_v = int(vs[1])

  if (valueMap[t_i] == 10 and valueMap[t_i] != t_v):
    valueMap[0] = 0
    break

  if (valueMap[t_i] > t_v and t_v != 0):
    valueMap[t_i] = t_v
valueMap = list(map(lambda v: 0 if v == 10 else v, valueMap))

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