import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
class Solution {
public static int find(ArrayList<Integer> arr)
{
int count=0;
for(int i=arr.get((arr.size()-1)/2);i>0;i--)
{
count=0;
for(int j=0;j<arr.size();j++)
{
if(arr.get(j)>=i)
count++;
else
break;
}
if(count>=i)
return i;
}
return 0;
}
public int solution(int[] citations) {
ArrayList<Integer> arr = new ArrayList<>();
for(int c:citations)
{
arr.add(c);
}
Collections.sort(arr, Collections.reverseOrder());
int answer = find(arr);
return answer;
}
}