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

#include <bits/stdc++.h>
using namespace std;
long long Length[1000 * (1 + 1000)], n, x, a[1001], Concern, Pos, Ppl;
vector<long long> Queues, adj[1001], Lengths;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> x;
  for (long long i = 1; i <= n; ++i) {
    cin >> a[i];
    if (a[i]) adj[a[i]].push_back(i);
  }
  for (long long i = 1; i <= n; ++i) {
    if (a[i] == 0) {
      Ppl = i;
      long long len = 0;
      while (Ppl) {
        ++len;
        if (Ppl == x) Concern = i, Pos = len;
        if (adj[Ppl].size())
          Ppl = adj[Ppl][0];
        else
          Ppl = 0;
      }
      if (Concern != i) Queues.push_back(len);
    }
  }
  for (long long i = 0; i < Queues.size(); ++i) cout << Queues[i] << "\n";
  for (long long i = Queues.size() - 1; i >= 0; --i) {
    vector<long long> Add;
    for (long long j = 0; j < Lengths.size(); ++j) {
      if (!Length[Lengths[j] + Queues[i]])
        Add.push_back(Lengths[j] + Queues[i]),
            Length[Lengths[j] + Queues[i]] = 1;
    }
    for (long long j = 0; j < Add.size(); ++j) Lengths.push_back(Add[j]);
    if (!Length[Queues[i]]) Lengths.push_back(Queues[i]), Length[Queues[i]] = 1;
  }
  cout << Lengths.size() + 1 << "\n";
  cout << Pos << "\n";
  sort(Lengths.begin(), Lengths.end());
  for (long long i = 0; i < Lengths.size(); ++i)
    cout << Pos + Lengths[i] << "\n";
  return 0;
}
