#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
int n, k, p[N], gk[256], gl[256];
int main() {
  cin >> n >> k;
  memset(gk, -1, sizeof(gk));
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  for (int i = 0; i < n; i++) {
    int cc = p[i];
    if (gk[cc] == -1) {
      int leftmost, len = 0;
      for (int j = cc; j >= 0 && gk[j] == -1 && len < k; j--) {
        leftmost = j;
        len++;
      }
      if (leftmost > 0 && len < k && gl[leftmost - 1] + len <= k) {
        len += gl[leftmost - 1];
        leftmost = gk[leftmost - 1];
      }
      for (int j = cc; j >= leftmost; j--) {
        gk[j] = leftmost;
        gl[j] = len;
      }
    }
    p[i] = gk[cc];
  }
  for (int i = 0; i < n; i++) {
    cout << p[i] << " ";
  }
  cout << "\n";
  return 0;
}
