N, M = gets.chomp.split(" ").map(&:to_i)
A = Array.new(N)

M.times do 
    s, c = gets.chomp.split(" ").map(&:to_i)
	if A[s-1] == nil
        A[s-1] = c
        if A[0] == 0
            A[4] = -1
        end
    else
      A[4] = -1
    end
end

if A[0] == nil
  A[0] = 1
end

if A.include?(-1) 
  puts "-1"
elsif A.include?(nil)
    A.map!{|x| x==nil ? 0 : x}
  	A.map!(&:to_s)
  if A.inject(:+).to_i != 0
    puts "#{A.inject(:+).to_i}"
  else
    puts "-1"
  end
end
