#include <bits/stdc++.h>
const int MAX = 100010;
using namespace std;
int par[MAX], n, k, x;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  memset(par, -1, sizeof par);
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    if (par[x] != -1)
      cout << par[x] << ' ';
    else {
      int st = x;
      while (st > 0 and par[st - 1] == -1 and x - st + 1 < k) --st;
      while (st > 0 and x - par[st - 1] + 1 <= k) st = par[st - 1];
      for (int i = st; i <= x; ++i) par[i] = st;
      cout << par[x] << ' ';
    }
  }
  return 0;
}
