#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T m, T n) {
  while (n) {
    T t = m % n;
    m = n;
    n = t;
  };
  return m;
}
template <typename T>
T exgcd(T a, T b, T& sa, T& ta) {
  T q, r, sb = 0, tb = 1, sc, tc;
  sa = 1, ta = 0;
  if (b) do
      q = a / b, r = a - q * b, a = b, b = r, sc = sa - q * sb, sa = sb,
      sb = sc, tc = ta - q * tb, ta = tb, tb = tc;
    while (b);
  return a;
}
template <typename T>
T mul_inv(T a, T b) {
  T t1 = a, t2 = b, t3;
  T v1 = 1, v2 = 0, v3;
  T x;
  while (t2 != 1)
    x = t1 / t2, t3 = t1 - x * t2, v3 = v1 - x * v2, t1 = t2, t2 = t3, v1 = v2,
    v2 = v3;
  return (v2 + b) % b;
}
template <typename T>
T powmod(T a, T b, T MOD) {
  if (b < 0) return 0;
  T rv = 1;
  while (b) (b % 2) && (rv = (rv * a) % MOD), a = a * a % MOD, b /= 2;
  return rv;
}
const int maxn = 1e5 + 7;
const int maxk = 256;
int n, k;
int p[maxn];
int key[256];
int main(int argc, char* argv[]) {
  std::cin.sync_with_stdio(false);
  std::cin.tie(nullptr);
  cin >> n >> k;
  {
    memset(key, -1, sizeof(key));
    for (int i = 1; i <= n; i++) {
      cin >> p[i];
      if (key[p[i]] == -1) {
        int mi = max(p[i] - k + 1, 0);
        int start = -1;
        int kstart = -1;
        for (int j = p[i] - 1; j >= mi; j--) {
          if (key[j] != -1) {
            kstart = j;
            start = key[j];
            break;
          }
        }
        if (start >= 0 && p[i] - start <= k - 1) {
          for (int j = kstart; j <= p[i]; j++) key[j] = start;
        }
        if (key[p[i]] == -1) {
          while (key[mi] != -1) mi++;
          int mm = mi;
          while (mi <= p[i]) key[mi++] = mm;
        }
      }
      cout << key[p[i]] << " ";
    }
    cout << endl;
  }
  return 0;
}
