#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n = 0, k = 0;
  cin >> n >> k;
  vector<int> p(n);
  for (auto &i : p) cin >> i;
  vector<int> grp(256, -1);
  for (int i = 0; i < n; ++i) {
    if (grp[p[i]] == -1) {
      int x = p[i];
      while (x >= max(0, p[i] - k + 1) && grp[x] == -1) --x;
      if (x == max(-1, p[i] - k)) {
        ++x;
        grp[x] = x;
      } else {
        if (p[i] - grp[x] >= k) {
          ++x;
          grp[x] = x;
        }
      }
      for (int j = x + 1; j <= p[i]; ++j) grp[j] = grp[x];
    }
    p[i] = grp[p[i]];
  }
  for (auto i : p) cout << i << " ";
}
