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 = []
if N == 1:
    for i in range(M):
        s,c = map(int,input().split())
        o.append(o)
    if same(o):
        if o[0] == 0:
            print(-1)
        else:
            print(o[0])
    else:
        print(-1)
if N == 2:
    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)
    if same(h) and same(t):
        h.append(0)
        t.append(0)
        ans = h[0]+t[0]
        if ans==0:
            print(-1)
        else:
            print(ans)
    else:
        print(-1)

if N == 3:
    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)
    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:
            print(-1)
        else:
            print(ans)
    else:
        print(-1)