#include <bits/stdc++.h>
int compare(const void *a, const void *b) {
  return *(long long int *)a - *(long long int *)b;
}
char subset[1009][1009];
void abc(int set[], int n, int sum) {
  int i, j;
  for (i = 0; i <= n; i++) subset[0][i] = 1;
  for (i = 1; i <= sum; i++) subset[i][0] = 0;
  for (i = 1; i <= sum; i++) {
    for (j = 1; j <= n; j++) {
      subset[i][j] = subset[i][j - 1];
      if (i >= set[j - 1])
        subset[i][j] = subset[i][j] || subset[i - set[j - 1]][j - 1];
    }
  }
}
int main() {
  int n, x, arr[1009], ar[1009] = {}, l = 0, set[1009], m = 0, j, i, a;
  scanf("%d", &n), scanf("%d", &x);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a);
    arr[a] = i;
    if (a == 0) ar[l++] = i;
  }
  int lalit = 0;
  for (i = 0; i < l; i++) {
    if (ar[i] == x)
      lalit = 1;
    else {
      int count = 1;
      j = arr[ar[i]];
      if (j != 0) {
        while (1) {
          if (j == x) {
            lalit = count + 1;
            count = -1;
            break;
          }
          j = arr[j];
          count++;
          if (j == 0) break;
        }
      }
      if (count != -1) set[m++] = count;
    }
  }
  abc(set, m, n + 1);
  printf("%d\n", lalit);
  for (i = 1; i <= n; i++)
    if (subset[i][m] == 1) printf("%d\n", lalit + i);
  return 0;
}
