N,M = map(int, input().split())
ans = 0
count1 = []
count2 = []
count3 = []
for _ in range(M):
  s, c = map(int,input().split())
  if s <= N:
    if s == 1 and not c in count1 and c != 0:
      ans += 100*c
      count1.append(c)
    elif s == 1 and c == 0:
      print(-1)
      exit(0)
    elif s == 2 and not c in count2:
      ans += 10*c
      count2.append(c)
    elif s == 3 and not c in count3:
      ans += 1*c
      count3.append(c)
  else:
    print(-1)
    exit(0)
if N == 3 and ans < 100:
  ans+=100
elif N == 2 and ans < 10:
  ans += 10
if len(count1) > 1 or len(count2) > 1 or len(count3) > 1:
  print(-1)
  exit(0)
print(ans)