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 _set(long long N, long long pos) { return N = N | (1 << pos); }
long long _reset(long long N, long long pos) { return N = N & ~(1 << pos); }
bool _check(long long N, long long pos) { return (bool)(N & (1 << pos)); }
bool _upper(char a) { return a >= 'A' && a <= 'Z'; }
bool _lower(char a) { return a >= 'a' && a <= 'z'; }
bool _digit(char a) { return a >= '0' && a <= '9'; }
long long dx[] = {1, -1, 0, 0, -1, -1, 1, 1};
long long dy[] = {0, 0, 1, -1, -1, 1, -1, 1};
vector<vector<long long> > g;
long long t[1010], ch, x, f, pos, n;
bool vis[1010];
void dfs(long long u) {
  if (!vis[u]) vis[u] = true;
  ch++;
  if (u == x) pos = ch, f = 1;
  for (auto i : g[u]) {
    dfs(i);
  }
}
set<long long> res;
void subsetSums(long long arr[], long long n) {
  long long total = 1 << n;
  for (long long i = 0; i < total; i++) {
    long long sum = 0;
    for (long long j = 0; j < n; j++)
      if (i & (1 << j)) sum += arr[j];
    res.insert(sum + pos);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> x;
  g.resize(n + 5);
  for (long long i = 1; i <= n; i++) {
    long long a;
    cin >> a;
    if (!a) {
      t[i] = 1;
      continue;
    }
    g[a].push_back(i);
  }
  vector<long long> cl;
  for (long long i = 1; i <= n; i++) {
    if (t[i]) {
      dfs(i);
      if (!f) cl.push_back(ch);
      ch = 0, f = 0;
    }
  }
  long long arr[110], n = 0;
  for (auto i : cl) arr[n++] = i;
  subsetSums(arr, n);
  for (auto i : res) cout << i << '\n';
  return 0;
}
