#include <bits/stdc++.h>
using namespace std;
int A[100010];
int sz[100010];
int n, k, a;
set<int> S;
map<int, int> M;
int main() {
  cin >> n >> k;
  for (int i = 0; i <= 255; i++) S.insert(i);
  for (int i = 1; i <= n; i++) {
    cin >> a, A[i] = a;
    if (M[a]) continue;
    int b = *S.lower_bound(a - k + 1);
    if (sz[b - 1] + a - b + 1 <= k) b -= sz[b - 1];
    int sabit = b;
    while (b <= a) M[b] = sabit, sz[b] = a - sabit + 1, S.erase(b), b++;
  }
  for (int i = 1; i <= n; i++) cout << M[A[i]] << " ";
}
