#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, a[100005], t[300], x = 0, r[300];
  memset(t, -1, sizeof(t));
  memset(r, 0, sizeof(r));
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (t[a[i]] == -1) {
      int in = -1;
      for (int j = a[i]; j >= 0; j--)
        if (t[j] == -1 && a[i] - j + 1 <= k)
          in = j;
        else if (t[j] != -1 && a[i] - t[j] + 1 <= k) {
          in = j;
        }
      int y = 0, l = 0;
      if (t[in] == -1)
        y = in, l = a[i] - in + 1;
      else
        y = t[in], l = a[i] - t[in] + 1;
      for (int j = in; j <= a[i]; j++) t[j] = y, r[j] = l;
    }
  }
  for (int i = 0; i < n; i++) cout << t[a[i]] << " ";
}
