#include <bits/stdc++.h>
using namespace std;
const int N = 2e6+9;
int n,m,l=1,r=0;
int a[N],q[N];
int main()
{
cin >> n >> m;
for (int i = 1; i <= n; i++)cin >> a[i];
for (int i = 1; i <= n - 1; i++)
{
cout << a[q[l]];
if (i - q[l] + 1 > m && l <= r)l++;
while (a[i] < a[q[r]] && l <= r)r--;
q[++r] = i;
}
}