#include <cstdio>
int N, K, l, r, a[1000009], v[1000009], p[1000009];
int main() {
	scanf("%d %d", &N, &K);
	for (int i = 0; i < N; i++) scanf("%d", &a[i]);
	for (int i = 0; i < K; i++) {
		while (l != r && v[r - 1] >= a[i]) r--;
		v[r] = a[i], p[r++] = i;
	}
	for (int i = K; i <= N; i++) {
		printf(i == N ? "%d\n" : "%d ", v[l]);
		if (p[l] == i - K) l++;
		while (l != r && v[r - 1] >= a[i]) r--;
		v[r] = a[i], p[r++] = i;
	}
	return 0;
}
