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