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