#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
  }
  vector<int> pal(256);
  vector<int> used(256, 0);
  vector<int> ost(256);
  for (int i = 0; i <= 255; i++) {
    pal[i] = i;
  }
  for (int i = 1; i <= n; i++) {
    if (used[p[i]] == 0) {
      int now = k;
      int t;
      for (t = p[i]; t >= 0 && p[i] - t + 1 <= k; t--) {
        if (used[t]) {
          break;
        }
      }
      if (t < 0) {
        t = 0;
        for (int j = t; j <= p[i]; j++) {
          used[j] = 1;
          pal[j] = pal[t];
          ost[j] = k - (p[i] - t + 1);
        }
      } else if (used[t]) {
        if (ost[t] >= p[i] - t) {
          int temp = ost[t];
          for (int j = p[i]; j >= t; j--) {
            pal[j] = pal[t];
            used[j] = 1;
            ost[j] = temp - p[i] + t;
          }
        } else {
          for (int j = t + 1; j <= p[i]; j++) {
            pal[j] = pal[t + 1];
            used[j] = 1;
            ost[j] = k - p[i] + t;
          }
        }
      } else {
        for (int j = t + 1; j <= p[i]; j++) {
          pal[j] = pal[t + 1];
          used[j] = 1;
          ost[j] = 0;
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << pal[p[i]] << " ";
  }
  return 0;
}
