def same(h):
    if len(h)==0:
        return True
    else:
        if len(set(h))==1:
            return True
        else:
            return False

N,M = map(int,input().split())
if M == 0:
    print(1)
    exit()
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)
    elif s == 3:
        o.append(tmp)
ans = -1

if same(o) and same(h) and same(t):
    h.append(0)
    t.append(0)
    o.append(0)
    ans = h[0]+t[0]+o[0]
    if ans == 0:
        ans = -1
if N == 1:
    ans //= 100
elif N == 2:
    ans //= 10
print(ans)
