#include <bits/stdc++.h>
using namespace std;
int n, k;
int p[100050];
int key[300];
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  int mg = 0;
  for (int i = 0; i < 300; i++) {
    key[i] = -1;
  }
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  key[0] = 0;
  for (int i = 0; i < n; i++) {
    if (key[p[i]] == -1) {
      int t = p[i] - 1;
      while (key[t] == -1 && p[i] - t <= k - 1) {
        t--;
      }
      if (p[i] - t == k) {
        int nk = t + 1;
        while (t < p[i]) {
          t++;
          key[t] = nk;
        }
      } else {
        if (p[i] - key[t] <= k - 1) {
          int nk = key[t];
          while (t < p[i]) {
            t++;
            key[t] = nk;
          }
        } else {
          int nk = t + 1;
          while (t < p[i]) {
            t++;
            key[t] = nk;
          }
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cout << key[p[i]] << " ";
  }
  cout << endl;
}
