n, m = map(int, input().split())

s = [0] * m
c = [0] * m


for i in range(m):
  s[i], c[i] = map(int, input().split())

max_ans = []

if all(i != 1 for i in s):
  print(-1)

else:
  new_s = [str(n) for n in s]

  for i in range(len(new_s)):
    if s[i] == 1:
      max_ans.append(c[i])

  if all(i == 0 for i in max_ans):
    print(-1)
  else:
    # print(max_ans)


    min_ans = c[s.index(max(s))]
    # print((s[s.index(max(s))] - 1))
    ans = min(max_ans) * 100 + min_ans * 10 ** (2 - (s[s.index(max(s))] - 1))
    print(ans)

  # print(new_s.index('1'))
