#include <bits/stdc++.h>
using namespace std;
long long int combi(long long int n, long long int k) {
  long long int ans = 1;
  k = k > n - k ? n - k : k;
  long long int j = 1;
  for (; j <= k; j++, n--) {
    if (n % j == 0) {
      ans *= n / j;
    } else if (ans % j == 0) {
      ans = ans / j * n;
    } else {
      ans = (ans * n) / j;
    }
  }
  return ans;
}
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int findlcm(vector<long long int> arr, long long int n) {
  long long int ans = arr[0];
  for (long long int i = 1; i < n; i++)
    ans = (((arr[i] * ans)) / (gcd(arr[i], ans)));
  return ans;
}
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, k;
  cin >> n >> k;
  vector<long long int> arr;
  long long int x;
  for (long long int i = 0; i < n; i++) {
    cin >> x;
    arr.push_back(x);
  }
  long long int clr[256];
  for (long long int i = 0; i < 256; i++) clr[i] = -1;
  for (long long int i = 0; i < arr.size(); i++) {
    if (clr[arr[i]] == -1) {
      long long int num = -1;
      for (long long int j = arr[i]; j >= 0; j--) {
        if (clr[j] != -1) {
          num = j;
          break;
        }
      }
      if (num == -1) {
        for (long long int j = max((long long int)0, arr[i] - k + 1);
             j <= arr[i]; j++) {
          clr[j] = max((long long int)0, arr[i] - k + 1);
        }
      } else {
        long long int cho = clr[num];
        long long int p = num;
        while (num >= 0 && clr[num] == cho) num--;
        num++;
        if (num + k - 1 >= arr[i]) {
          for (long long int j = num; j <= arr[i]; j++) clr[j] = cho;
        } else {
          long long int x = max(p + 1, arr[i] - k + 1);
          for (long long int j = x; j <= arr[i]; j++) clr[j] = x;
        }
      }
    }
  }
  for (long long int i = 0; i < arr.size(); i++) cout << clr[arr[i]] << " ";
  return 0;
}
