#include <bits/stdc++.h>
using namespace std;
int n, m, a[100003], ada[100003];
int main() {
  cin >> n >> m;
  memset(ada, -1, sizeof ada);
  ;
  for (int i = 1; i <= n; i++) cin >> a[i];
  int las = 0;
  for (int i = 1; i <= n; i++) {
    int las = -1;
    for (int j = a[i]; j >= 0; j--) {
      if (ada[j] != -1) {
        las = ada[j];
        break;
      }
    }
    if (las == -1 || las + m - 1 < a[i]) {
      int itu;
      for (int j = a[i]; j >= max(a[i] - m + 1, 0); j--) {
        if (ada[j] != -1) {
          break;
        }
        itu = j;
      }
      for (int j = a[i]; j >= max(a[i] - m + 1, 0); j--) {
        if (ada[j] != -1) {
          break;
        }
        ada[j] = itu;
      }
      cout << ada[a[i]] << ' ';
      continue;
    }
    if (las + m - 1 >= a[i]) {
      for (int j = las; j <= a[i]; j++) ada[j] = las;
    }
    cout << las << ' ';
  }
}
