#include <bits/stdc++.h>
using namespace std;
const int N = 256;
int sz[N], par[N];
int f(int x) {
  if (x == par[x]) return x;
  return par[x] = f(par[x]);
}
int main() {
  for (int i = 0; i < N; ++i) sz[i] = 1, par[i] = i;
  int n, k;
  cin >> n >> k;
  int a;
  while (n--) {
    scanf("%d", &a);
    int temp = a;
    while (a - 1 >= 0) {
      int c = f(a - 1), t = f(a);
      if (c == t) {
        --a;
        continue;
      }
      if (sz[c] + sz[t] <= k) {
        par[t] = c;
        sz[c] += sz[t];
      } else
        break;
    }
    printf("%d ", f(temp));
  }
  cout << endl;
  return 0;
}
