// Arup Guha
// 11/3/2013
// Solution to 2013 South East Regional Division 2 Problem E: Cousins

import java.util.*;

public class cousins {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();
		int ID = stdin.nextInt();
		int loop = 1;

		// Go through each case.
		while (n != 0) {

			// Read in the tree and store our query node index.
			int IDindex = 0;
			node[] tree = new node[n];
			for (int i=0; i<n; i++) {
				int data = stdin.nextInt();
				tree[i] = new node(data);
				if (data == ID)
					IDindex = i;
			}

			// Store level of each person.
			int cur = 1;
			int index = 1;
			int prevdist = 0;

			LinkedList<Integer> q = new LinkedList<Integer>();

			// Run a BFS through this tree.
			q.offer(0);
			while (q.size() > 0) {

				int item = q.poll();
				if (index < n) {

					// Figure out item's children and enqueue them.
					int nextStart = index;
					while (index+1 < n && tree[index+1].ID - tree[index].ID == 1) {
						q.offer(index);
						index++;
					}
					int nextEnd = index;

					// Update so we start at the next spot.
					q.offer(index);
					index++;

					// Update parent and child information for this range.
					tree[item].setChildRange(nextStart, nextEnd);
					for (int i=nextStart; i<=nextEnd; i++)
						tree[i].setParent(item);
				}
			}

			// Solve the trivial cases of no cousins.
			if (tree[IDindex].parent == node.NOPARENT)
				System.out.println("0");
			else if (tree[tree[IDindex].parent].parent == node.NOPARENT)
				System.out.println("0");

			// Typical case.
			else {
				int dad = tree[IDindex].parent;
				int grandpa = tree[tree[IDindex].parent].parent;
				System.out.println(gen(tree, grandpa, 2) - gen(tree, dad, 1));
			}

			// Get next case.
			n = stdin.nextInt();
			ID = stdin.nextInt();
			loop++;
		}
	}

	public static int gen(node[] tree, int root, int numGens) {

		// Easy base case, just count yourself.
		if (numGens == 0) return 1;

		// Recursively add the answer from each of your kids.
		int sum = 0;
		for (int i=tree[root].lowChildID; i<=tree[root].highChildID; i++)
			sum += gen(tree, i, numGens-1);

		// This sum is it!
		return sum;
	}
}

class node {

	final public static int NOPARENT = -1;

	public int ID;
	public int lowChildID;
	public int highChildID;
	public int parent;

	// By default, a node is on its own. We set the rest later...
	public node(int value) {
		ID = value;
		parent = NOPARENT;
		lowChildID = 1;
		highChildID = 0;
	}

	public void setChildRange(int low, int high) {
		lowChildID = low;
		highChildID = high;
	}

	public void setParent(int par) {
		parent = par;
	}
}