#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
int a[MAXN], b[MAXN], f[260], n, k;
int main(void) {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    b[i] = a[i];
  }
  memset(f, -1, sizeof f);
  for (int i = 1; i <= n; ++i) {
    if (f[a[i]] == -1) {
      int low = -1;
      for (int j = a[i]; j >= a[i] - k + 1 && j >= 0; --j) {
        if (f[j] != -1) {
          if (f[j] >= a[i] - k + 1) low = f[j];
          break;
        }
        low = j;
      }
      for (int j = low; j <= a[i]; ++j) {
        f[j] = low;
      }
    }
    b[i] = f[a[i]];
  }
  for (int i = 1; i <= n; ++i) {
    cout << b[i] << ' ';
  }
  cout << '\n';
  return 0;
}
