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