#include <bits/stdc++.h>
using namespace std;

const int mx = 5e5+5;
int n, k, a[mx];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> a[i];

    multiset<int> s;
    int p1 = 1, p2 = 1 + k;

    for (int i = p1; i <= p2; i++)
        s.insert(a[i]);

    vector<int> ans;

    while (p1 != p2) {
        int mn = *s.begin();
        while (a[p1] != mn) {
            s.erase(s.find(a[p1]));
            p1++;
        }
        ans.push_back(mn);
        s.erase(s.find(a[p1]));
        p1++, ++p2;
        s.insert(a[p2]);
    }
    while (p1 <= n) {
        ans.push_back(a[p1++]);
    }

    for (auto x : ans)
        cout << x << ' ';
}