package com.codechef.javaapp;
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
LinkedList l = new LinkedList();
int n1;
while(true){
n1 = sc.nextInt();
if(n1 == -1){
break;
}
else{
l.addLast(n1);
}
}
l.nFromLast(sc.nextInt());
}
}
class LinkedList{
private Node head;
class Node{
int data;
Node next;
}
private int size;
private Node tail;
public void nFromLast(int n){
this.nFromLast(this.head ,n);
}
private void nFromLast(Node node,int n){
int len = 0;
Node temp;
while(node !=null){
node = node.next;
len++;
}
if(len<n){
return;
}
temp = node;
for(int i = 0;i<len-n+1;i++){
temp = temp.next;
}
System.out.print(temp.data);
}
public void addLast(int data){
Node nn = new Node();
nn.data = data;
nn.next = null;
if(size>0){
this.tail.next = nn;
}
if(size == 0){
this.head = nn;
this.tail = nn;
this.size=1;
}
else {
this.tail = nn;
this.size++;
}
}
}