#include <bits/stdc++.h>
using namespace std;
void fast_in_out() {
  std::ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
}
void pause() {}
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
int vis[263216];
int arr[221366];
int groub[123266];
int tok[122366];
int main() {
  fast_in_out();
  int n, k;
  cin >> n >> k;
  memset(tok, -1, sizeof tok);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    vis[arr[i]]++;
  }
  for (int i = 0; i < n; i++) {
    if (tok[arr[i]] != -1) {
      continue;
    }
    if (!i) {
      tok[arr[i]] = max(0, arr[i] - k + 1);
      groub[tok[arr[i]]]++;
      for (int j = arr[i] - 1; j >= 0 && j >= tok[arr[i]]; j--) {
        tok[j] = tok[arr[i]];
        groub[tok[arr[i]]]++;
        if (groub[tok[arr[i]]] == k) break;
      }
      int c = 1;
      continue;
    }
    int kk = k - 1;
    int j, ne = 1;
    bool f = 0, f2 = 0;
    for (j = arr[i] - 1; j >= 0; j--) {
      if (kk == 0) break;
      kk--;
      if (tok[j] != -1 && groub[tok[j]] + ne <= k) {
        f = 1;
        break;
      } else if (tok[j] != -1) {
        f2 = 1;
        break;
      }
      ne++;
    }
    if (f) {
      for (int m = j + 1; m <= arr[i]; m++) {
        tok[m] = tok[j];
        groub[tok[m]]++;
        f = 1;
      }
      continue;
    }
    kk = k;
    int gr = arr[i] - ne + 1;
    while (ne) {
      groub[gr]++;
      tok[arr[i] - ne + 1] = gr;
      ne--;
    }
  }
  for (int i = 0; i < n; i++) cout << tok[arr[i]] << " ";
  cout << '\n';
  pause();
  return 0;
}
