#include<stdio.h>
#include<stdlib.h>
typedef struct tree{
    int data;
    struct tree *left,*right;
}Node;
Node *root=NULL;
typedef struct queue{
    int data;
    Node *arr[20];
}Node1;
Node1 *q;
int f=0,r=-1;
void en(Node *root){
    q->arr[++r]=root;
}
Node de(){
    return q->arr[f++];
}
Node *create(int num){
    Node *newnode=(Node*)malloc(sizeof(Node));
    newnode->data=num;
    newnode->left=NULL;
    newnode->right=NULL;
    return newnode;
}
Node *insert(Node *root,int num){
    if(root==NULL)
    return create(num);
    if(num<root->data)
    root->left=insert(root->left,num);
    if(num>root->data)
    root->right=insert(root->right,num);
    return root;
}
int level(Node *root,int l){
    if(root==NULL)
    return 0;
    q=(Node1*)malloc(sizeof(Node1));
    f=0;
    r=-1;
    en(root);
    int cur=1;
    int sum=0;
    while(f<=r){
        int size=(r-f+1);
        sum=0;
        for(int i=0;i<size;i++){
            Node* temp=de();
            if(cur==l)
            sum+=temp->data;
            if(temp->left!=NULL)
            en(temp->left);
            if(temp->right!=NULL)
            en(temp->right);
        }
        if(cur==l)
        return sum;
        cur++;
    }
    return 0;
}
int main(){
    int n,i,num,l;
    if(scanf("%d",&n)!=1){
    printf("Invalid input");
    return 0;
}
    for(i=0;i<n;i++){
        scanf("%d",&num);
        root=insert(root,num);
    }
    scanf("%d",&l);
    int res=level(root,l);
    printf("%d",res);
    return 0;
}