import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.Scanner; import java.util.stream.Stream; import static java.lang.System.in; public class Main { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String[] inputs = reader.readLine().split(" "); int N = Integer.parseInt(inputs[0]); int M = Integer.parseInt(inputs[1]); inputs = reader.readLine().split(" "); int[] boxes = Stream.of(inputs).mapToInt(Integer::parseInt).toArray(); Arrays.sort(boxes); int index = 0; while (M != 0) { if (boxes[index] == 0) { index += 1; } else { boxes[index] -= 1; M -= 1; } } if (boxes[index] == 0) { System.out.println(index + 1); } else { System.out.println(index); } } }