#include <bits/stdc++.h>
using namespace std;
int n, k;
int p[100100];
pair<int, int> grp[260];
bool used[260];
int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> p[i];
  for (int i = 0; i < 260; i++) {
    grp[i] = {i, 1};
    used[i] = false;
  }
  for (int i = 0; i < n; i++) {
    if (used[p[i]]) {
      p[i] = grp[p[i]].first;
      continue;
    }
    int pos = p[i], cnt = 1;
    while (cnt < k && pos > 0 && !used[pos - 1]) {
      pos--;
      cnt++;
    }
    int rel = pos;
    if (pos > 0 && grp[pos - 1].second + cnt <= k) rel = grp[pos - 1].first;
    for (int j = rel; j <= p[i]; j++) {
      used[j] = true;
      grp[j].first = rel;
      grp[j].second = p[i] - rel + 1;
    }
    p[i] = grp[p[i]].first;
  }
  for (int i = 0; i < n; i++) cout << p[i] << ' ';
  return 0;
}
