#include <bits/stdc++.h>
using namespace std;
int a[265], n, k;
int main() {
  cin >> n >> k;
  for (int i = 0; i <= 255; i++) a[i] = -1;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    if (a[x] == -1)
      for (int ii = max(0, x - k + 1); ii <= x; ii++)
        if (a[ii] == -1 || a[ii] == ii) {
          for (int j = ii; j <= x; j++) a[j] = ii;
          break;
        }
    printf("%d ", a[x]);
  }
}
