#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
template <typename T_char>
T_char TL(T_char cX) {
  return tolower(cX);
};
template <typename T_char>
T_char TU(T_char cX) {
  return toupper(cX);
};
const int vy[] = {-1, -1, -1, 0, 1, 1, 1, 0},
          vx[] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
int p[101010];
int group[300];
int n, k;
int main() {
  cin >> n >> k;
  for (LL i = (0); i < (300); i++) group[i] = -1;
  for (LL i = (0); i < (n); i++) cin >> p[i];
  for (LL i = (0); i < (n); i++) {
    if (group[p[i]] == -1) {
      for (int j = max(p[i] - k + 1, 0); j <= p[i]; j++) {
        if (group[j] == -1 || group[j] == j) {
          for (int l = j; l <= p[i]; ++l) {
            group[l] = j;
          }
          break;
        }
      }
    }
  }
  for (LL i = (0); i < (n); i++) {
    if (i) cout << " ";
    cout << group[p[i]];
  }
  cout << endl;
}
