#include <bits/stdc++.h>
using namespace std;
int key[256];
int size[256];
int main() {
  ios::sync_with_stdio(0);
  memset(key, -1, sizeof(key));
  int n, k;
  cin >> n >> k;
  int x;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (key[x] != -1)
      cout << key[x] << " ";
    else {
      int j = 0;
      for (j = max(0, x - k + 1); j < 256; j++) {
        if (key[j] == -1 || key[j] + k - 1 >= x) {
          for (int l = j; l <= x; l++) key[l] = (key[j] == -1 ? j : key[j]);
          break;
        }
      }
      cout << key[x] << " ";
    }
  }
}
