#include <bits/stdc++.h>
using namespace std;
#define int              long long int
#define double           long double
inline int power(int a, int b) {
    int x = 1;
    while (b) {
        if (b & 1) x *= a;
        a *= a;
        b >>= 1;
    }
    return x;
}


const int M = 1000000007;
const int N = 3e5+9;
const int INF = 2e9+1;
const int LINF = 2000000000000000001;

//_ ***************************** START Below *******************************



vector<int> a;


int consistency1(int n, int k) {

	int s = 0, e = n-1;
	int ans = INF;
	
	while(s<=e){
		int mid = s + (e-s)/2;
		int first = lower_bound(begin(a), end(a), a[mid]) - begin(a);
		int last = upper_bound(begin(a), end(a), a[mid]) - begin(a) - 1;
		
		if( (last+1) % k != 0 ){
			ans = min(ans, a[mid]);
			e = first-1;
		}
		else{
			s = last+1;
		}
	}
	
	return ans;

}




//* Lock BS
//*   [  2   2   2   3   3   4   4   4   ]
//*      F   F   F   T   T   T   T   T   


int consistency2(int n, int k) {

	int s = 0, e = n-1;
	while(s<e){
		int mid = s + (e-s)/2;
		int lastIdx = upper_bound(begin(a), end(a), a[mid]) - begin(a) - 1;
		if( (lastIdx+1)%k != 0 ){
			e = mid;
		}
		else{
			s = lastIdx+1;
		}
	}
	
	
	return a[e];

}












int practice(int n, int k) {

	return 0;
}



void solve() {
    
	int n, k;
	cin >> n >> k;
	
	a.resize(n);
	
	for(int i=0; i<n; i++) cin >> a[i];
	
    
    // cout << consistency1(n, k) << " " << consistency2(n, k) << endl;
    cout << consistency1(n, k) << " " << practice(n, k) << endl;
	
}





int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}