N,M = gets.split.map(&:to_i)
S, C = M.times.map{gets.split.map(&:to_i)}.transpose
arr = Array.new(N+1, nil)

S.each_with_index do |s,i|
    if s == 1 && C[i] == 0
        puts -1
        exit
    end

    if arr[s] && C[i] != arr[s]
        puts -1
        exit
    end

    arr[s] = C[i]
end

ans = 0

N.times do |i|
    if arr[1+i]
        ans += arr[1+i] * (10 ** (3 - i - 1))
    end
end

puts ans
