#include <bits/stdc++.h>
using namespace std;
constexpr long long INF = 2e18;
constexpr long long MOD = 1e9 + 7;
constexpr long long MAXN = 2e5 + 3;
void solve() {
  long long n;
  cin >> n;
  long long k;
  cin >> k;
  vector<long long> arr(n);
  for (long long i = 0; i < n; ++i) {
    long long &x = arr[i];
    cin >> x;
  }
  vector<long long> ans(n);
  set<long long> s;
  set<long long> c;
  for (long long i = 0; i < 256; ++i) s.emplace(i);
  long long last = -INF;
  long long maxx = -1;
  for (long long i = 0; i < n; ++i) {
    pair<long long, long long> x = pair<long long, long long>(arr[i], i);
    long long v = -1;
    for (long long j = arr[i]; j >= max(0ll, arr[i] - k + 1); --j) {
      if (s.count(j)) {
        v = j;
      }
      if (c.count(j)) {
        v = j;
        break;
      }
    }
    for (long long i = v; i <= x.first; ++i) {
      if (s.count(i)) s.erase(i);
    }
    c.emplace(v);
    ans[i] = v;
  }
  for (long long x : ans) {
    cout << x << ' ';
  }
  cout << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  while (t--) solve();
}
