N , M = (map(int , input().split()))
A = []
for i in range(M):
    A.append(list(map(int , input().split())))
if N == 3:
    keta1 = 100
    keta2 = 10
    keta3 = 1
elif N == 2:
    keta1 = 10
    keta2 = 1
elif N == 1:
    keta1 = 1
num1 = 1000
num2 = 100
num3 = 10
for i in A:
    if i[0] == 1:
        num1 = min(num1 , i[1] * keta1)
if num1 == 1000:
    num1 = 0
for i in A:
    if i[0] == 2:
        num2 = min(num2 , i[1] * keta2)
if num2 == 100:
    num2 = 0
for i in A:
    if i[0] == 3:
        num3 = min(num3 , i[1] * keta3)
if num3 == 10:
    num3 = 0

if N == 1:
    ans = num1+num2+num3
elif num1 == 0:
    ans = -1
else:
    ans = num1+num2+num3
print(ans)