#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, k;
  cin >> n >> k;
  int r[257] = {};
  for (int i = 0; i < 257; i++) {
    r[i] = -1;
  }
  int p;
  for (int i = 0; i < n; i++) {
    cin >> p;
    if (r[p] == -1) {
      for (int j = (p - k + 1 >= 0) ? p - k + 1 : 0; j <= p; j++) {
        if (r[j] == -1) {
          for (int x = j; x <= p; x++) {
            if (r[x] != -1) break;
            r[x] = j;
          }
          break;
        } else if (r[j + 1] == -1) {
          if (r[j] + k - 1 >= p) {
            for (int x = j + 1; x <= p; x++) {
              r[x] = r[j];
            }
            break;
          }
        }
      }
    }
    cout << r[p] << ' ';
  }
  return 0;
}
