#include <stdio.h>

int main() {
	long long n, k, a[100000000], town = 0, count = 0;
	scanf("%lld%lld", &n, &k);
	for (int i = 0; i < n; i++)scanf("%lld", &a[i]);
	town = a[0];
	for (int j = 0; j < k-1; j++) {
		printf("%lld\n", town);
		town = a[town-1];
	}
    printf("dd\n");
	printf("%lld", town);
}