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

x = 0
if m == 0:
    if n == 1:
        x = 0
    else:
        x = 10 ** (n - 1)

else:
    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)