https://pintia.cn/problem-sets/994805342720868352/problems/994805354762715136
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class Main{
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(reader.readLine());
int[] arr = new int[n];
String[] str = reader.readLine().split(" ");
for (int i = 0; i < n; i++) {
arr[i] = Integer.parseInt(str[i]);
}
reader.close();
Arrays.sort(arr);
for (int i = n; i > 0; i--) {
if(arr[n - i] > i){
System.out.println(i);
return;
}
}
System.out.println(0);
}
}