#include <bits/stdc++.h>
using namespace std;
constexpr int INF = 1e9 + 5;
constexpr long long INFL = 1e18;
const int maxp = 255;
int n, k;
int r[maxp + 5], d[maxp + 5];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  fill(r, r + maxp + 2, -1);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (r[a] != -1) {
      cout << r[a] << " ";
      continue;
    }
    int j = a;
    int cnt = 0;
    int x;
    while (j >= 0 && cnt < k) {
      if (r[j] == -1) {
        x = j, d[a] = ++cnt;
        j--;
      } else {
        if (cnt + d[j] <= k) x = r[j], d[a] = cnt + d[j];
        break;
      }
    }
    j++;
    cout << x << " ";
    for (int l = j; l <= a; l++) {
      r[l] = x;
    }
  }
  return 0;
}
