class Solution {
public:
    int specialArray(vector<int>& nums) {
        sort(nums.begin(), nums.end());
        int n = nums.size();
        for(int i = 0; i < n; i++){
            int j = n-i;
            if(nums[i]>=j && (i==0 || nums[i-1]<j)){
                return j;
            }
        }
        return -1;
    }
};