#include <bits/stdc++.h>
using namespace std;
int sum[100005], F[100005];
int n, k;
int Find(int a) {
  if (F[a] == a)
    return a;
  else
    return F[a] = Find(F[a]);
}
int main() {
  while (cin >> n >> k) {
    int p;
    for (int i = 0; i <= 256; i++) {
      sum[i] = 1;
      F[i] = i;
    }
    for (int i = 0; i < n; i++) {
      cin >> p;
      while (p >= 1) {
        if (Find(p) != p)
          break;
        else if (sum[Find(p - 1)] + sum[Find(p)] > k)
          break;
        else {
          sum[Find(p - 1)] += sum[Find(p)];
          F[p] = Find(p - 1);
        }
        p--;
      }
      cout << F[p] << " ";
    }
    cout << endl;
  }
  return 0;
}
