#include <bits/stdc++.h>
using namespace std;
int Par[300];
bool Used[300];
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) {
    int p;
    scanf("%d", &p);
    if (!Used[p]) {
      int Min = max(0, p - k + 1);
      int Last = p;
      int New;
      while (!Used[Last] && Last > Min) Last--;
      if (Used[Last]) {
        if (p - Par[Last] + 1 <= k) {
          int newP = Par[Last];
          for (int j = Last + 1; j <= p; j++) {
            Used[j] = 1;
            Par[j] = newP;
          }
        } else {
          int newP = Last + 1;
          for (int j = Last + 1; j <= p; j++) {
            Used[j] = 1;
            Par[j] = newP;
          }
        }
      } else {
        int newP = Last;
        for (int j = Last; j <= p; j++) {
          Used[j] = 1;
          Par[j] = newP;
        }
      }
    }
    printf("%d ", Par[p]);
  }
}
