import sys
n, m = map(int, input().split())
s = [list(map(int, input().split())) for i in range(m)]

x = 0
for j in range(m - 1):
    for i in range(j + 1):
        if s[i][0] == s[j + 1][0] and s[i][1] != s[j + 1][1]:
            x -= 1

if x != -1:
    y = [0] * n
    for k in range(m):
        y[s[k][0] - 1] = s[k][1]
    if y[0] == 0:
        x -= 1
    else:
        for l in range(n):
            x += y[l] * (10 ** (n - l - 1))

print(x)