n, m = map(int,input().split())
d = {0:0}
ans = 0
for i in range(m):
    s, c = map(int,input().split())
    if s in d:
        if d[s] == c:
            continue
        else:
            ans = -100000000000
    else:
        d[s] = c
        ans += (10**(3-s))*c

if 1 in d:
    if d[1] == 0:
        print(-1)
    else:
        ans += 100

if ans > 0:
    print(ans)
