#include<bits/stdc++.h>
bool possible(vector<int>& arr,int day , int totalB , int pairs){
	int count=0;
	int numberOfB=0;
	for(int i=0; i<arr.size();i++){
		if(arr[i]<=day){
			count++;
		}
		else{
			numberOfB+=(count)/pairs;
			count=0;
		}
	}
	numberOfB+=(count)/pairs;

	if(numberOfB>=totalB) return true;
	else return false;
}
int roseGarden(vector<int> arr, int k, int m)
{
	int mini=INT_MAX;	
	int maxi=INT_MIN;

	if((m*k) > arr.size()) return -1;

	for(int i=0;i<arr.size();i++){
		mini = min(mini,arr[i]);
		maxi = max(maxi,arr[i]);
	}

	int low=mini;
	int high=maxi;
	int ans = -1;
	while(low<=high){
		int mid = (low+high)/2;
		if(possible(arr, mid, m, k)){
			ans=mid;
			high=mid-1;
		}
		else low=mid+1;
	}
	return ans;
}