#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[100005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  memset(a, int(0x3f3f3f3f), sizeof(a));
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (a[x] == int(0x3f3f3f3f)) {
      for (int j = x - k + 1; j <= x; j++) {
        if (a[j] == int(0x3f3f3f3f) || a[j] == j) {
          for (int kk = j; kk <= x; kk++) {
            a[kk] = j;
          }
          break;
        }
      }
    }
    cout << a[x] << " ";
  }
  cout << "\n";
}
