#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, k;
  cin >> n >> k;
  vector<long long> v(n);
  for (long long i = 0; i < n; i++) cin >> v[i];
  set<pair<long long, long long> > grps;
  for (long long i = 0; i < n; i++) {
    auto it = grps.upper_bound({v[i], 1000});
    if (it == grps.begin()) {
      grps.insert({max(0ll, v[i] - k + 1), v[i]});
      v[i] = max(0ll, v[i] - k + 1);
    } else {
      it--;
      if (it->first <= v[i] && it->second >= v[i]) {
        v[i] = it->first;
      } else {
        long long st = it->first;
        if ((v[i] - st) < k) {
          grps.erase(it);
          grps.insert({st, v[i]});
          v[i] = st;
        } else {
          long long en = max(it->second + 1, v[i] - k + 1);
          grps.insert({en, v[i]});
          v[i] = en;
        }
      }
    }
  }
  for (long long i = 0; i < n; i++) cout << v[i] << " ";
  return 0;
}
