#include <bits/stdc++.h>
using namespace std;
int main() {
  int arr[100005];
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; cin >> arr[i++])
    ;
  int ass[260];
  for (int i = 0; i < 260; ass[i++] = -1)
    ;
  if (arr[0] == 0) ass[0] = 0;
  for (int i = 0; i < n; i++) {
    if (ass[arr[i]] == -1) {
      for (int cnt = k; cnt > 0; cnt--) {
        if (arr[i] - cnt + 1 >= 0 && ass[arr[i] - cnt + 1] == -1) {
          for (int j = cnt; j > 0; j--) {
            if (arr[i] - j + 1 >= 0) ass[arr[i] - j + 1] = arr[i] - cnt + 1;
          }
          break;
        } else {
          if (arr[i] - cnt + 1 >= 0 && arr[i] - ass[arr[i] - cnt + 1] < k) {
            for (int j = cnt; j > 0; j--) {
              if (arr[i] - j + 1 >= 0) ass[arr[i] - j + 1] = arr[i] - cnt + 1;
            }
            break;
          }
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cout << ass[arr[i]] << " ";
  }
  return 0;
}
