#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, k;
int a[N];
int vis[300];
int main() {
  cin >> n >> k;
  memset(vis, -1, sizeof vis);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (vis[a[i]] != -1) {
      cout << vis[a[i]] << ' ';
      continue;
    }
    for (int j = max(0, a[i] - k + 1); j <= a[i]; j++) {
      if (vis[j] == -1 || (a[i] - vis[j]) < k) {
        for (int kk = j; kk <= a[i]; kk++) {
          vis[kk] = j;
        }
        cout << j << ' ';
        break;
      }
    }
  }
  return 0;
}
