#include <bits/stdc++.h>
using namespace std;
int n, x;
int a[1005];
bool c[1005];
int pos = 1;
vector<int> b;
set<int> comb;
int visit(int m) {
  if (a[m] == 0) return m == x ? 9999 : 1;
  int ans = 1 + visit(a[m]);
  if (m == x) {
    pos = ans;
    return 9999;
  }
  return ans;
}
int main() {
  cout.precision(15);
  cin >> n >> x;
  for (long long i = 0; i < (n); ++i) {
    cin >> a[i + 1];
    c[a[i + 1]] = 1;
  }
  for (long long i = 0; i < (n); ++i) {
    if (c[i + 1] == 0) {
      int t = visit(i + 1);
      if (t < 9999) b.push_back(t);
    }
  }
  comb.insert(0);
  for (long long i = 0; i < (b.size()); ++i) {
    vector<int> temp;
    set<int>::iterator beg = comb.begin();
    for (long long j = 0; j < (comb.size()); ++j) {
      temp.push_back(*beg + b[i]);
      beg++;
    }
    comb.insert(temp.begin(), temp.end());
  }
  for (set<int>::iterator beg = comb.begin(); beg != comb.end(); beg++) {
    cout << pos + *beg << endl;
  }
}
