#include <bits/stdc++.h>
using namespace std;
int a[100001], b[100001];
int t[260];
int main() {
  memset(t, -1, sizeof(t));
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    if (t[a[i]] != -1) {
      b[i] = t[a[i]];
    } else {
      int j;
      for (j = a[i]; j >= 0 && j >= a[i] - k + 1; j--) {
        if (t[j] != -1) {
          if (t[j] >= a[i] - k + 1) {
            b[i] = t[j];
            for (int m = j + 1; m <= a[i]; m++) {
              t[m] = t[j];
            }
            break;
          } else {
            b[i] = j + 1;
            for (int m = j + 1; m <= a[i]; m++) {
              t[m] = j + 1;
            }
            break;
          }
        }
      }
      if (j < 0 || j == a[i] - k) {
        b[i] = j + 1;
        for (int m = j + 1; m <= a[i]; m++) {
          t[m] = b[i];
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (i != n - 1)
      cout << b[i] << ' ';
    else
      cout << b[i] << endl;
  }
  return 0;
}
