#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const int INF = (int)(1e9 + 1e6);
const long long LINF = (long long)(4e18);
const double EPS = 1e-14;
mt19937 ggen;
void solve();
int main() {
  iostream::sync_with_stdio(false);
  cin.tie(0);
  ggen = mt19937(1337);
  solve();
}
void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> col(n);
  for (int i = 0; i < n; ++i) {
    cin >> col[i];
  }
  vector<int> c(256, 0);
  vector<int> ans(256, 0);
  for (int i = 0; i < 256; ++i) ans[i] = i;
  for (int i = 0; i < n; ++i) {
    int kt = col[i];
    int kt1 = max(0, kt - k + 1);
    int pos = ans[kt];
    int rg = k - c[kt];
    int jj = pos;
    int lg = c[kt];
    while (jj > kt1 && rg > 0) {
      rg--;
      jj--;
      lg++;
      if (c[jj] + lg > k) break;
      pos = jj;
    }
    cout << ans[pos] << " ";
    pos = ans[pos];
    int ft = kt - pos + 1;
    for (int j = pos; j <= kt; ++j) {
      c[j] = max(ft, c[j]);
      ans[j] = pos;
    }
  }
}
