#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1000+5;
int n,m;
int tot=0;
int to[N],id[N],pos[N];
vector<int>v[N];
bool vis[N]={0};
void dfs(int pt){
id[pt]=tot;v[tot].push_back(pt);
pos[pt]=v[tot].size()-1;vis[pt]=1;
if (!vis[to[pt]])dfs(to[pt]);
}
int main(){
freopen ("shuffle.in","r",stdin);
freopen ("shuffle.out","w",stdout);
scanf ("%d%d",&n,&m);
for (int i=1;i<=n;i++){
int x;scanf("%d",&x);
to[x]=i;
}
for (int i=1;i<=n;i++){
if (!vis[i])tot++,dfs(i);
}
for (int i=1;i<=n;i++){
int cnt=v[id[i]].size();
int p=m%cnt,x=pos[i];
printf("%d\n",v[id[i]][((x-p)%cnt+cnt)%cnt]);
}
return 0;
}