str = gets.split
N,M = str[0].to_i, str[1].to_i

a = Array.new(M){Array.new(2)}
for i in 0...M do
    str = gets.split
    a[i][0],a[i][1] = str[0].to_i, str[1].to_i
end

if N == 1
    b = 10
    for i in 0...M do
        c = a[i][1]
        if b == 10
            b = c
        elsif b != c
            b = -1
        end
    end
    answer = b
    if answer == 10
        answer = 0
    end
    puts answer
else
    b = Array.new(N,10)
    answer = 0
    for i in 0...M do
        c = a[i][1]
        d = a[i][0]
        if b[d-1] == 10
            b[d-1] = c
        elsif b[d-1] != c
            answer = -1
        end
    end
    if b[0] == 0
        answer = -1
    end
    if answer == -1
        puts answer
    else
        for i in 0...M do
            if b[-i-1] == 10 && i == M-1
                answer += 10**i
            elsif b[-i-1] == 10
                answer += 0
            else
                answer += b[-i-1] * (10**i)
            end
        end
        puts answer
    end
end