#include <stdio.h>
#include <stdlib.h>
#define N 10005
int a[N];
int cmp(const void* a, const void* b)
{
return *(int*)a - *(int*)b;
}
void Swap(int* a, int* b)
{
int t;
t = *a;
*a = *b;
*b = t;
}
int main(void)
{
int n, m;
scanf("%d", &n);
scanf("%d", &m);
int i, j, k;
int v;
for (i = 1; i <= n; i++)
scanf("%d", &a[i]);
for (i = n - 1; i >= 1; i--)
{
if (a[i] < a[i + 1])
{
v = i; break;
}
}
for (k = 0; k < m; k++)
{
for (i = n; i >= 1; i--)
{
if (i == v)
{
i = n; v--;
}
for (j = i - 1; j >= v; j--)
if (a[j] < a[i])
{
Swap(&a[i], &a[j]);
qsort(a + j + 1, n - j, sizeof(int), cmp);
v = j - 1;
i = j = 0;
/*for (int q = 1; q <= n; q++)
printf("%d ", a[q]);
printf("\n");*/
}
}
}
for (i = 1; i <= n; i++)
printf("%d ", a[i]);
}