#include <bits/stdc++.h>
using namespace std;
int n, k;
const int K = 256, N = 100100;
int id[K];
int sz[K];
int a[N];
bool done[K];
int getid(int i) { return id[i] == i ? i : id[i] = getid(id[i]); }
int getsz(int i) { return id[i] == i ? sz[i] : getsz(getid(i)); }
void uni(int i, int j) {
  assert(!done[j]);
  id[j] = i;
  ++sz[i];
  done[i] = done[j] = true;
}
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  cin >> n >> k;
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < K; ++i) id[i] = i;
  for (int i = 0; i < K; ++i) sz[i] = 1;
  for (int i = 0; i < n; ++i)
    if (!done[a[i]]) {
      int l = a[i];
      while (l && !done[l - 1] && a[i] - l + 1 < k) --l;
      bool getprev = l && done[l - 1] && getsz(l - 1) + a[i] - l + 1 <= k;
      for (int j = l + !getprev; j <= a[i]; ++j) uni(getid(l - getprev), j);
    }
  for (int i = 0; i < n; ++i) cout << getid(a[i]) << " ";
  cout << endl;
}
