#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> color(256, -1);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (color[a] != -1)
      cout << color[a] << ' ';
    else {
      int cur = a, l = 1;
      while (cur > 0 && l < k) {
        if (color[cur - 1] == -1) {
          cur--;
          l++;
        } else
          break;
      }
      if (l < k && cur > 0) {
        if (a - color[cur - 1] <= k - 1) {
          for (int i = cur; i <= a; i++) {
            color[i] = color[cur - 1];
          }
        }
      }
      if (color[a] == -1)
        for (int i = cur; i <= a; i++) {
          color[i] = cur;
        }
      cout << color[a] << ' ';
    }
  }
  cout << endl;
}
