import itertools

N, M = map(int, input().split())

keta1 = 10
keta2 = 10
keta3 = 10
for i in range(M):
  keta, kazu = map(int, input().split())
  if keta == 1 and kazu != 0:
    keta1 = min(keta1, kazu)
  elif keta == 2:
    keta2 = min(keta2, kazu)
  elif keta == 3:
    keta3 = min(keta3, kazu)

if keta1 == 10:
  print(-1)
else:
  if keta2 == 10:
    keta2 = 0
  if keta3 == 10:
    keta3 = 0
  print(keta1*100 + keta2*10 + keta3)