#include <bits/stdc++.h>
using namespace std;
int pixel[100002];
map<int, int> m, val;
char p = 'o', n = '-';
int main() {
  m[0] = 1;
  val[0] = 0;
  int a, b, c, d, temp, i, j, k, vi;
  cin >> a >> c;
  for (i = 1; i <= a; i++) scanf("%d", &pixel[i]);
  for (i = 1; i <= a; i++) {
    b = pixel[i];
    if (m[b] == 1) continue;
    d = 1;
    for (j = b - 1; j >= 0; j--) {
      if (m[j] == 1) {
        temp = val[j];
        if (b - temp >= c) {
          vi = max(b - c + 1, j + 1);
          for (k = vi; k <= b; k++) {
            val[k] = vi;
            m[k] = 1;
          }
        } else {
          for (k = j + 1; k <= b; k++) {
            val[k] = temp;
            m[k] = 1;
          }
        }
        break;
      }
    }
  }
  for (i = 1; i <= a; i++) printf("%d ", val[pixel[i]]);
  return 0;
}
