#include <bits/stdc++.h>
using namespace std;
int n, k;
int ar[200010], br[200010], c[1000];
void fnc(int id, int v) {
  if (c[v] != -1) return;
  int l = max(0, v - k + 1);
  while (c[l] != -1) l++;
  if (l == 0) {
    for (int i = l; i <= v; i++) {
      c[i] = l;
    }
  } else {
    int pre = c[l - 1];
    if (pre + k - 1 >= v) {
      for (int i = l; i <= v; i++) {
        c[i] = pre;
      }
    } else {
      for (int i = l; i <= v; i++) {
        c[i] = l;
      }
    }
  }
}
int main(int argc, char const *argv[]) {
  scanf("%d %d", &n, &k);
  memset(c, -1, sizeof c);
  for (int i = 0; i < n; i++) {
    scanf("%d", ar + i);
  }
  for (int i = 0; i < n; i++) {
    fnc(i, ar[i]);
  }
  for (int i = 0; i < n; ++i) {
    cout << c[ar[i]] << ' ';
  }
  return 0;
}
