#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int a[N];
int f[N];
int find(int x) { return f[x] < 0 ? x : f[x] = find(f[x]); }
int n, k;
bool merge(int x, int y) {
  int fx = find(x);
  int fy = find(y);
  if (fx == fy) return true;
  if (-(f[fx] + f[fy]) > k)
    return false;
  else {
    if (fx > fy) swap(fx, fy);
    f[fx] += f[fy];
    f[fy] = fx;
    return true;
  }
}
void solve() {
  cin >> n >> k;
  for (int i = 0; i < 256; ++i) f[i] = -1;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) {
    int fx = a[i];
    for (int j = fx - 1; j >= max(0, fx - k + 1); --j) {
      if (!merge(fx, j)) break;
    }
  }
  for (int i = 1; i <= n; ++i) cout << find(a[i]) << ' ';
  cout << '\n';
}
int main() {
  int T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
