N, M = map(int, input().split())
ans = -1
x = [-1] * 3
for _ in range(M):
    s, c = map(int, input().split())
    if s == 1 and c == 0 and N > 1:
        break
    s = N - s
    if x[s] >= 0 and x[s] != c:
        break
    x[s] = c
else:
    ans = max(x[0], 0)
    if x[2] > 0:
        ans += (x[2] * 100)
        if x[1] > 0:
            ans += (x[1] * 10)
    else:
        if x[1] > 0:
            ans += (x[1] * 10)
        elif x[1] == 0:
            ans += 100
print(ans)