#include <bits/stdc++.h>
using namespace std;
long long n, k, x, par[256], dp[256], tmp, s;
bitset<256> b;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 0; i <= 255; i++) {
    par[i] = i;
  }
  for (int i = 1; i <= n; i++) {
    cin >> x;
    if (b[x]) {
      cout << par[x] << " ";
    } else {
      for (int j = k; j >= 1; j--) {
        s = max((long long)0, x - j + 1);
        if (par[s] == s && !b[s]) {
          tmp = s;
          cout << tmp << " ";
          break;
        } else if (b[s]) {
          if (k + par[s] - 1 >= x) {
            tmp = par[s];
            cout << tmp << " ";
            break;
          }
        }
      }
      for (int j = tmp; j <= x; j++) {
        par[j] = tmp;
        b[j] = true;
      }
      dp[tmp] = x - tmp + 1;
    }
  }
  cout << '\n';
  return 0;
}
