#include <bits/stdc++.h>
using namespace std;
template <class T>
T gcd(T x, T y) {
  while (T t = x % y) x = y, y = t;
  return y;
}
const double eps = 1e-10;
const double PI = acos(-1.);
const int INF = 1000000000;
const int MOD = 1000000007;
const double E = 2.7182818284590452353602874713527;
bool isdig(char x) { return x >= '0' && x <= '9'; }
bool isup(char x) { return x >= 'A' && x <= 'Z'; }
bool islow(char x) { return x >= 'a' && x <= 'z'; }
bool islet(char x) { return isup(x) || islow(x); }
int nxt[1005], in[1005];
int N, K;
void get_data() {
  scanf("%d%d", &N, &K);
  K--;
  memset(nxt, -1, sizeof(nxt));
  ;
  memset(in, 0, sizeof(in));
  ;
  for (int i = 0; i < N; i++) {
    int bef;
    scanf("%d", &bef);
    if (!bef) continue;
    bef--;
    nxt[bef] = i;
    in[i] = 1;
  }
}
vector<int> vec;
int sum;
int L;
int dis;
void get_len() {
  vec.clear();
  for (int i = 0; i < N; i++) {
    if (in[i]) continue;
    bool has = 0;
    int l = 0, v;
    v = i;
    l = 1;
    if (v == K) has = 1, dis = 1;
    int tdis = 1;
    while (nxt[v] != -1) {
      l++;
      v = nxt[v];
      tdis++;
      if (v == K) has = 1, dis = tdis;
    }
    if (has)
      L = l;
    else
      vec.push_back(l);
  }
  sum = 0;
  for (int i = 0; i < ((int)(vec).size()); i++) sum += vec[i];
}
int cal(int tot) {
  bool mk[1005];
  memset(mk, 0, sizeof(mk));
  ;
  mk[0] = 1;
  for (int i = 0; i < ((int)(vec).size()); i++) {
    for (int j = tot; j >= 0; j--) {
      if (j < vec[i]) break;
      mk[j] |= mk[j - vec[i]];
    }
  }
  for (int i = tot; i >= 0; i--) {
    if (mk[i]) return i;
  }
  return -1;
}
bool ok(int loc) {
  int mst = cal(loc - 1);
  if (sum - mst <= N - loc - L + 1)
    return 1;
  else
    return 0;
}
void run() {
  get_len();
  for (int i = 0; i < N; i++) {
    if (ok(i + 1)) cout << i + dis << '\n';
  }
}
int main(int argc, char *argv[]) {
  {
    get_data();
    run();
  }
  return EXIT_SUCCESS;
}
