#include <bits/stdc++.h>
using namespace std;
int key[(long long int)(1e5 + 10)], p[(long long int)(1e5 + 10)];
bool done[(long long int)(1e5 + 10)];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    int j = p[i];
    if (done[j]) continue;
    while (!done[j] && p[i] - j < k && j >= 0) done[j] = 1, j--;
    if (j >= 0) {
      if (p[i] - key[j] + 1 <= k)
        key[p[i]] = key[j];
      else
        key[p[i]] = j + 1;
    } else
      key[p[i]] = 0;
    for (j = j + 1; j <= p[i]; j++) key[j] = key[p[i]];
  }
  for (int i = 0; i < n; i++) cout << key[p[i]] << " ";
  cout << endl;
  return 0;
}
