#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(void) {
    
    long long N, K;
    scanf("%lld", &N); scanf("%lld", &K);

    int towns[N];
    for (int i=0; i<N; i++) {
        scanf("%d", &towns[i]);
    }

    vector<bool> visited(N+1, false);
    vector<int> visited_locations;
    int location=1;
    int i=0;

    while (1) {
        if (visited[location]) {
            break;
        }

        visited_locations.push_back(location);
        visited[location] = 1;
        location = towns[location - 1];
    }

    vector<int>::iterator it = find(visited_locations.begin(), 
                                    visited_locations.end(), 
                                    location);

    int index = distance(visited_locations.begin(), it);
    cout << index << endl;

    int distance = visited_locations.size() - index;
    cout << distance << endl;

    for (int i=0; i<visited_locations.size(); i++) printf("%d ", visited_locations[i]);
    printf("\n");
    for (int i=0; i<visited.size(); i++) printf("%s ", visited[i] ? "true":"false");
    printf("\n");

    if (K <= index) {
        printf("%d\n", visited_locations[K]);
    } else {
        printf("%d\n", visited_locations[(int) (index + (K - index) % distance)]);
    }

}