C = gets.to_i N = gets.to_i a = gets.split.map(&:to_i) dp = Array.new(C + 1, Float::INFINITY) dp[0] = 0 a.each do |x| (0..C-x).each do |y| dp[y + x] = [dp[y + x], dp[y] + 1].min end end ans = if dp [C] < Float::INFINITY dp[C] else -1 end puts ans