#include
using namespace std;
class node{
public:
int data;
node *next;
node(int value){
data=value;
next=NULL;
}
};
void Inserthead(node *& head,int value){
if(head==NULL){
head=new node(value);
return;
}
node n=new node(value);
n->next=head;
head=n;
}
void insertAt_tail(node&head,int value){
if(head==NULL){
head= new node(value);
return;
}
node n=new node(value);
nodetemp=head;
while(temp->next!=NULL){
temp=temp->next;
}
temp->next=n;
}
void print(node head){
while(head!=NULL){
cout<data<<" ";
head=head->next;
}
}
node * input_func(){
int d;
cin>>d;
node head=NULL;
while(d!=-1){
insertAt_tail(head,d);
cin>>d;
}
return head;
}
int kth_element(node* head,int key){
node * slow=head;
node * fast=head;
int count=1;
while(count<=3){
fast=fast->next;
count++;
}
while(fast!=NULL){
slow=slow->next;
fast=fast->next;
}
return slow->data;
}
int main(){
node * head=input_func();
int n;
cin>>n;
cout<<kth_element(head,n);
cout<<endl;
return 0;
}