#include <bits/stdc++.h>
const int N = 1e5 + 9;
using namespace std;
int n, m;
int vis[N], v[N];
int main() {
  scanf("%d%d", &n, &m);
  memset(vis, 0, sizeof vis);
  memset(v, -1, sizeof v);
  int tmp;
  for (int i = 0; i < n; i++) {
    scanf("%d", &tmp);
    if (v[tmp] != -1) {
      printf("%d", v[tmp]);
      if (i == n - 1)
        printf("\n");
      else
        printf(" ");
      for (int j = v[tmp]; j <= tmp; j++) {
        vis[j] = 1;
      }
      continue;
    }
    int pos = tmp;
    for (int j = tmp; j >= max(tmp - m + 1, 0); j--) {
      if (vis[j]) break;
      pos = j;
      vis[j] = 1;
    }
    for (int j = pos; j <= tmp; j++) {
      v[j] = pos;
    }
    for (int j = tmp + 1; j <= pos + m - 1; j++) {
      if (!vis[j]) {
        v[j] = pos;
      } else
        break;
    }
    printf("%d", v[tmp]);
    if (i == n - 1)
      printf("\n");
    else
      printf(" ");
  }
}
