// Arup Guha
// 4/10/2021
// Solution to 2021 USACO April Bronze Problem: Acowdemia I

import java.util.*;
import java.io.*;

public class a {

	public static void main(String[] args) throws Exception {
	
		// Read in the first line.
		BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer tok = new StringTokenizer(stdin.readLine());
		int n = Integer.parseInt(tok.nextToken());
		int numAdd = Integer.parseInt(tok.nextToken());
		
		// Read in the values.
		int[] vals = new int[n];
		tok = new StringTokenizer(stdin.readLine());
		for (int i=0; i<n; i++)
			vals[i] = Integer.parseInt(tok.nextToken());
		Arrays.sort(vals);
		
		// Sweeps to the next spot after the h-index cutoff.
		int curIdx = n-1;
		while (curIdx>=0 && vals[curIdx] >= n-curIdx) curIdx--;
		
		// We went 1 too far.
		curIdx++;
		int curH = n-curIdx;
		
		// Greedily add.
		int added = 0;
		for (int i=n-1; i>=0; i--) {
			if (added >= numAdd) break;
			if (vals[i] == curH) {
				vals[i]++;
				added++;
			}
		}
		
		// Resolve for the h-index.
		curIdx = n-1;
		while (curIdx>=0 && vals[curIdx] >= n-curIdx) curIdx--;		
		System.out.println(n-1-curIdx);
	}
}