#include <bits/stdc++.h>
using namespace std;
int rep[300], a[100010];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i <= 255; i++) rep[i] = -1;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    if (rep[a[i]] == -1) {
      int r = a[i] - 1, change = 0, change1 = 0;
      while (r >= 0 && r >= a[i] + 1 - k) {
        if (rep[r] != rep[r + 1]) {
          change++;
          if (change == 2) break;
          change1 = r + 1;
        }
        r--;
      }
      if (change == 0) {
        for (int j = r + 1; j <= a[i]; j++) rep[j] = r + 1;
      } else if (change == 1) {
        if (r >= 0 && rep[r] == rep[r + 1])
          for (int j = change1; j <= a[i]; j++) rep[j] = change1;
        else
          for (int j = change1; j <= a[i]; j++) rep[j] = r + 1;
      } else {
        for (int j = r + 1; j <= a[i]; j++) rep[j] = r + 1;
      }
    }
    a[i] = rep[a[i]];
  }
  for (int i = 0; i < n; i++) cout << a[i] << " ";
  cout << "\n";
}
