#include <bits/stdc++.h>
using namespace std;
int n, k;
int A[100005], G[260];
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> A[i];
  for (int i = 0; i <= 256; i++) G[i] = -1;
  for (int i = 1; i <= n; i++) {
    if (G[A[i]] == -1) {
      int j;
      for (j = 1; j <= k && A[i] - j + 1 >= 0 && G[A[i] - j + 1] == -1; j++)
        ;
      if (j > k) j--;
      if (A[i] - j + 1 < 0) j--;
      if (G[A[i] - j + 1] != -1) j--;
      int g = A[i] - j + 1, prim = G[A[i] - j];
      if (prim >= 0 && A[i] - prim + 1 <= k) {
        for (int x = prim; x <= A[i]; x++) G[x] = prim;
      } else {
        for (int x = g; x <= A[i]; x++) G[x] = g;
      }
    }
    cout << G[A[i]] << " ";
  }
  return 0;
}
