20 20
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 10 4
0 1 4 2 7 0 10 0 5 8
 10 7
10 8 6 5 0 0 0 4 3 9
 10 1
8 7 0 2 0 10 0 0 3 5
 10 7
7 9 2 10 0 0 0 3 5 1
 10 2
10 0 9 0 0 4 2 6 8 0
 10 2
0 7 0 10 8 0 4 2 3 0

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 3
4
8
9
 1
5
6
10
 2
4
5
7
8
10
 1
2
6
7
 1
2
3
4
6
7
8
9
 4
5
6
7
8

import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;

/**
 * Created by KC on 4/8/14.
 */
public class EKG {
    static BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter printWriter= new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

    public static void main(String[] args) throws IOException{
        String[] p = bufferedReader.readLine().trim().split(" ");
        int n = Integer.parseInt(p[0]);
        int idx = Integer.parseInt(p[1]);

      //  int n = 6;
      //  int idx = 2;

        int[] count = new int[n+1];
        int[] array = new int[n+1];
        p = bufferedReader.readLine().trim().split(" ");
      // String[] p = {"0","0","1","0","4","5"};



        for(int i = 1; i <= n; i++){
            array[i] = Integer.parseInt(p[i-1]);
            count[i] += 1;

            if(array[i] != 0){
                if(array[i] < i){
                    int t = i;
                    while (array[t] != 0) t = array[t];
                    count[t] += count[i];
                }
                else {
                    count[array[i]] += count[i];

                }
            }
        }



        int fin = idx;
        int pre = 0;
        while (array[fin] != 0){
             fin = array[fin];
             pre++;
        }

        ArrayList<Integer> group = new ArrayList<Integer>();
        for(int i = 1; i <= n; i++){
            if(array[i] == 0 && i != fin){
                group.add(count[i]);
            }
        }

        pre++;
        printWriter.println(pre);
        ArrayList<Integer> result = new ArrayList<Integer>();
        HashSet<Integer> set = new HashSet<Integer>();

        int size = group.size();
        int[][] results = new int[size][size];

        for(int i = 0; i < size; i++){
            results[i][i] = group.get(i);
            if(!set.contains(results[i][i])){
                result.add(results[i][i]);
                set.add(results[i][i]);
            }
        }


        for(int i = 0; i < size; i++){
            for(int j = i+1; j < size; j++){
                results[i][j] = results[i][j-1] + group.get(j);
                if(!set.contains(results[i][j])){
                    result.add(results[i][j]);
                    set.add(results[i][j]);
                }
            }
        }

        Collections.sort(result);
        for(int i = 0; i < result.size();i++)
            printWriter.println(result.get(i)+pre);


        printWriter.flush();
        printWriter.close();

    }
}
