# Read input k, n = gets.not_nil!.split.map(&.to_i) # Read array of n integers a = Array(Int32).new(n) n.times do |i| a[i] = gets.not_nil!.to_i end # Sort the array a.sort! # Process elements (0...n).each do |i| k -= a[i] if k < 0 puts i exit end end puts n