#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  long long a[n + 1];
  vector<pair<long long, long long>> range;
  for (long long i = 0; i <= 256; i += k) {
    range.push_back(make_pair(i, i + k - 1));
  }
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
  }
  long long ma[300];
  memset(ma, -1, sizeof(ma));
  long long temp = k - 1;
  for (long long i = 0; i < n; i++) {
    long long num = a[i], take = a[i];
    for (long long temp = 0; temp < k; temp++) {
      if (num == 0) {
        take = 0;
        ma[a[i]] = 0;
        break;
      }
      if (ma[num] == -1) {
        take = num;
      } else {
        if (ma[num] >= (a[i] - k + 1) && ma[num] <= (a[i] + k - 1))
          take = min(ma[num], take);
        break;
      }
      num--;
    }
    ma[a[i]] = take;
    ma[take] = take;
  }
  for (long long i = 0; i < n; i++) {
    cout << ma[a[i]] << " ";
  }
  return 0;
}
