#include <bits/stdc++.h>
using namespace std;
int main() {
  int n = 0, k = 0;
  cin >> n >> k;
  vector<int> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  vector<int> c(256);
  vector<bool> used(256, false);
  for (int i = 0; i < 256; i++) {
    c[i] = i;
  }
  vector<int> ans(n, 0);
  for (int i = 0; i < n; i++) {
    if (used[p[i]]) {
      continue;
    } else {
      int t = p[i];
      used[t] = true;
      while (t - 1 >= 0 && p[i] - t + 1 < k && !used[t - 1]) {
        used[t] = true;
        t--;
        used[t] = true;
      }
      if (p[i] - t == k - 1) {
        for (int j = t; j <= p[i]; j++) {
          c[j] = t;
        }
      } else if (t == 0) {
        for (int j = t; j <= p[i]; j++) {
          c[j] = 0;
        }
      } else if (used[t - 1]) {
        if (p[i] - c[t - 1] < k) {
          for (int j = t; j <= p[i]; j++) {
            c[j] = c[t - 1];
          }
        } else {
          for (int j = t; j <= p[i]; j++) {
            c[j] = t;
          }
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cout << c[p[i]] << ' ';
  }
  cout << endl;
}
