#include <bits/stdc++.h>
using namespace std;
const int maxn = 270;
int vis[maxn];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  int p;
  memset(vis, -1, sizeof(vis));
  for (int i = 0; i < n; i++) {
    scanf("%d", &p);
    if (vis[p] == -1) {
      int j = p;
      while (j >= p - k + 1 && j >= 0 && vis[j] == -1) j--;
      if (j == -1)
        j = 0;
      else if (vis[j] + k - 1 >= p)
        j = vis[j];
      else
        j = max(j + 1, p - k + 1);
      for (int k = j; k <= p; k++) {
        vis[k] = j;
      }
    }
    printf("%d%c", vis[p], (i == n - 1) ? '\n' : ' ');
  }
}
