import collections

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

if M == 0:
    result = -1

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

result = 0
if result == 0:
    result = -1
    
if len(mydict) != 0:
    maxNum = max(mydict.keys())
    
    if maxNum < N:
        result = -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

    if result == 0:
        result = -1

print(result)