import collections

N, M = map(int, input().split())
SC = []
for i in range(M):
    array = list(map(int, input().strip().split()))
    SC.append(array)

mydict = {}
count = 0
for sc in SC:
    mydict[sc[0]] = sc[1]

maxNum = max(mydict.keys())
result = 0
if maxNum < N:
    print(-1)
else:
    for k, v in mydict.items():
        if k == 1:
            result = result + v * 100
        elif k == 2:
            result = result + v * 10
        elif k == 3:
            result = result + v * 1

print(result)