package yukicoder.No156; import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int N, M; List arrC = new ArrayList(); N = in.nextInt(); M = in.nextInt(); for (int i = 0; i < N; i++) { int C = in.nextInt(); arrC.add(C); } Collections.sort(arrC); int cnt = 0; int sum = 0; while (M > 0) { M -= arrC.get(cnt++); } if (M < 0) { cnt = cnt-1; } System.out.println(cnt); } }