#include <bits/stdc++.h>
using namespace std;
set<int> st;
int main() {
  int n, k, x;
  cin >> n >> k;
  int key[256];
  for (int i = 0; i < 256; ++i) key[i] = -1;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    if (key[x] == -1) {
      for (int j = max(x - k + 1, 0);; j++) {
        if (key[j] == -1 || key[j] == j) {
          for (int l = j; l <= x; ++l) key[l] = j;
          break;
        }
      }
    }
    cout << key[x] << " ";
  }
}
