#include <bits/stdc++.h>
using namespace std;
int colors[1000];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, k;
  cin >> n >> k;
  k--;
  for (int i = 0; i < 256; i++) colors[i] = -256;
  for (int m = 0; m < n; m++) {
    int x, c = 256;
    cin >> x;
    int i;
    for (i = x; i >= max(x - k, 0) && colors[i] == -256; i--)
      ;
    if (i != -1 && colors[i] + k >= x)
      for (int j = i; j <= x; j++) colors[j] = colors[i];
    else {
      i++;
      if (i != x + 1)
        for (int j = i; j <= x; j++) colors[j] = i;
      else if (i == x + 1)
        i = colors[x];
    }
    cout << colors[x] << " ";
  }
}
