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:
        for k in range(len(slist)):
            if slist[k] == s:
                if clist[k] == c:
                    ans = ans + 0
                else:
                    ans = -1
                    break
        k = k + 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)