#include <bits/stdc++.h>
template <typename T>
T max(T x, T y) {
  return (x > y) ? x : y;
}
template <typename T>
T min(T x, T y) {
  return (x < y) ? x : y;
}
template <typename T>
bool chkmax(T &x, T y) {
  return (x >= y) ? 0 : (x = y, 1);
}
template <typename T>
bool chkmin(T &x, T y) {
  return (x <= y) ? 0 : (x = y, 1);
}
template <typename T>
T read(T &in) {
  in = 0;
  char ch;
  T f = 1;
  while (!isdigit(ch = getchar()))
    if (ch == '-') f = -1;
  while (isdigit(ch)) in = in * 10 + ch - '0', ch = getchar();
  return in *= f;
}
static const int max1 = 100000 + 11;
int n, k;
int p[max1], b[301];
int main() {
  read(n), read(k);
  for (int i = (1), ir = (n); i <= (ir); ++i) read(p[i]);
  memset(b, -1, sizeof b);
  for (int i = (1), ir = (n); i <= (ir); ++i) {
    int j = p[i], end = max(0, p[i] - k + 1);
    if (b[j] != -1) {
      printf("%d ", b[j]);
      continue;
    }
    while (j >= end && -1 == b[j]) --j;
    ++j;
    if (-1 == b[j])
      for (int w = (j), wr = (p[i]); w <= (wr); ++w) b[w] = j;
    if (j > 0 && b[j - 1] != -1 && p[i] - b[j - 1] + 1 <= k) {
      for (int w = (j), wr = (p[i]); w <= (wr); ++w) b[w] = b[j - 1];
    }
    printf("%d ", b[j]);
  }
  putchar(10);
  return 0;
}
