#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int f[258], sum[258];
int n, k, a[N], ans[N];
void init() {
  for (int i = 0; i <= 256; i++) {
    f[i] = i;
    sum[i] = 1;
  }
}
int father(int x) {
  if (f[x] == x) return x;
  return f[x] = father(f[x]);
}
void unio(int x, int y) {
  int fat1 = father(x);
  int fat2 = father(y);
  if (fat1 != fat2) f[max(fat1, fat2)] = min(fat1, fat2);
}
int main() {
  while (cin >> n >> k) {
    memset(sum, 0, sizeof(sum));
    init();
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) {
      for (int j = a[i] - 1; j >= 0 && j >= a[i] - k; j--) {
        if (father(a[i]) != father(j) &&
            sum[father(a[i])] + sum[father(j)] <= k) {
          int x1 = father(a[i]);
          int x2 = father(j);
          unio(x1, x2);
          sum[father(a[i])] = sum[x1] + sum[x2];
        } else
          break;
      }
      ans[i] = father(a[i]);
    }
    for (int i = 0; i < n - 1; i++) cout << ans[i] << ' ';
    cout << ans[n - 1] << endl;
  }
  return 0;
}
