#include <stdio.h>
#include <stdlib.h>
typedef struct SNode
{
int data;
struct SNode* next;
}SNode;
void push(SNode* pS, int num)
{
SNode* pR;
pR = (SNode*)malloc(sizeof(SNode));
pR->data = num;
pR->next = pS->next;
pS->next = pR;
}
void pop(SNode* pS)
{
if (pS->next == NULL)
return;
SNode* pR;
pR = pS->next;
pS->next = pR->next;
free(pR);
}
void gettop(SNode* pS)
{
if (pS->next == NULL)
printf("-1");
else
printf("%d", pS->next->data);
}
int main()
{
int n, num, m, i = 0, j = 0;
SNode* pS;
pS = (SNode*)malloc(sizeof(SNode));
pS->next = NULL;
scanf("%d", &n);
for (i = 0; i < n; i++)
{
scanf("%d", &num);
push(pS, num);
}
scanf("%d", &m);
for (j = 0; j < m; j++)
{
pop(pS);
}
gettop(pS);
return 0;
}