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