import java.util.*; public class Main { static int[][] map; static int[][] ans; static int[] vx = new int[] {1,0,-1,0}; static int[] vy = new int[] {0,1,0,-1}; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int[] list = new int[n]; for(int i = 0; i < n; i++) { list[i] = sc.nextInt(); } Arrays.sort(list); int count = 0; for(int i = 0; i < m; i++) { list[count]--; while(list[count] == 0) { count++; } } System.out.println(count); } }