def set_list(es):
    if len(es) == 0:
        return True
    return len(list(set(es))) == 1

N,M = map(int,input().split())
h = []
t = []
o = []
for i in range(M):
    s,c = map(int,input().split())
    tmp = c *(10**(-s+3))
    if s == 1:
        h.append(tmp)
    elif s == 2:
        t.append(tmp)
    else:
        o.append(tmp)
ans = -1
if set_list(h) and set_list(t) and set_list(o):
    h.append(0)
    t.append(0)
    o.append(0)
    ans = h[0]+t[0]+o[0]
    if ans == 0:
        ans = -1
print(ans)