N, M = map(int,input().split())

ans = 0
slist = []
clist = []

for i in range(M):
    s, c = map(int,input().split())
    if s in slist and c in clist:
        ans += 0
    if s in slist and c not in clist:
        ans = -1
    if s not in slist:
        slist.append(s)
        clist.append(c)
        if s == 1:
            ans = ans + c*100
        if s == 2:
            ans = ans + c*10
        if s == 3:
            ans = ans + c

        
print(ans)
