#include<bits/stdc++.h>

using namespace std;

class node{

    public:

    int data;

    node *left, *right;

    node(int data__){

        data = data__;

        left = right = NULL;

    }

};

node* make_tree(vector<int> a){

    node *head = NULL, *ptr = NULL;

    int n = a.size();

    if(n == 0)

        return NULL;

    head = new node(a[0]);

    ptr = head;

    queue<node*> q;

    q.push(ptr);

    int i = 0;

    while(i < n and !q.empty()){

        ptr = q.front();

        q.pop();

        if(i < n and a[i] != -1){

            ptr -> left = new node(a[i]);

            i++;

            q.push(ptr -> left);

        }

        if(i < n and a[i] != -1){

            ptr -> right = new node(a[i]);

            i++;

            q.push(ptr -> right);

        }



    }

    return head;

}

node* ptr1(node* head, int k){

    if(head == NULL){

        return NULL;

    }

    if(head -> data == k){

        return head;

    }

    node* l = ptr1(head -> left, k);

    if(l)

        return l;

    node* r = ptr1(head -> right, k);

    return r;

}

int count(node* head){

    if(head == NULL)

    return 0;

    int l = count(head -> left);

    int r = count(head -> right);

    return 1 + l + r;

}

int main(){

    int n, x, k;

    cin >> n >> x >> k;

    vector<int> v(n);

    for(int i = 0; i < n; i++){

        int y;

        cin >> y;

        v.push_back(y);

    }

    node* head = make_tree(v);

    node* ptr = ptr1(head, k);

    int rightcount = count(ptr -> right);

    int leftcount = count(ptr -> left);

    if(rightcount > x - rightcount or leftcount > x - leftcount){

        cout << 1 << "\n";

    }

    else{

        cout << 0 << "\n";

    }

}