#include <bits/stdc++.h>
const long long mod = 1e9 + 7;
using namespace std;
int n, a[100005], k, dd[300];
void Nhap() {
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> a[i];
}
void fill(int start, int end) {
  for (int i = start; i <= end; ++i) dd[i] = start;
}
void process() {
  int x;
  for (int i = 0; i <= 256; i++) dd[i] = -1;
  for (int i = 1; i <= n; ++i) {
    if (dd[a[i]] < 0) {
      if (dd[max(0, a[i] - k + 1)] < 0)
        fill(max(0, a[i] - k + 1), a[i]);
      else {
        for (int j = max(0, a[i] - k + 1); j <= a[i]; ++j)
          if ((dd[j] < 0) || (a[i] - dd[j] + 1 <= k)) {
            x = j;
            break;
          }
        fill(x, a[i]);
      }
    }
  }
  for (int i = 1; i <= n; ++i) cout << dd[a[i]] << " ";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  Nhap();
  process();
  return 0;
}
