c = gets.to_i n = gets.to_i a = gets.split.map &:to_i INF = 10**9 dp = Array.new(c + 1, INF) dp[0] = 0 a.each do |x| (c + 1 - x).times { |i| dp[i + x] = dp[i] + 1 if dp[i + x] > dp[i] + 1 } end puts dp[c] != INF ? dp[c] : -1