n, m = map(int, input().split())

sc = {} 
for i in range(m):
    S, C = list(map(int, input().split()))
    if S in sc and sc[S] != C:
        print(-1)
        exit()

    sc[S] = C

    if 1 in sc:
        if sc[1] == 0:
            print(-1)
            exit()

    if 1 in sc and 2 in sc:
        if sc[1] == 0 and sc[2] == 0:
            print(-1)
            exit()
    if 1 in sc and 2 in sc and 3 in sc:
        if sc[1] == 0 and sc[2] == 0 and sc[3] == 0:
            print(0)
            exit()


ans = 0
if 1 in sc:
    #print(sc[1]*100)
    ans += sc[1]*100
if 2 in sc:
    #print(sc[2]*10)
    ans += sc[2]*10
if 3 in sc:
    #print(sc[3]*1)
    ans += sc[3]*1
print(ans)
#print(sc)



