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] > t_v and t_v != 0):
    valueMap[t_i] = t_v
if ((len(valueMap) != 1 and valueMap[0] == 0) or 10 in valueMap):
  print(-1)
else:
  print("".join(map(lambda v: "0" if v == 10 else str(v), valueMap)))