#include<malloc.h>
#include<string.h>
typedef struct Node
{
int data;
struct Node *next;
}NODE,*PNODE;
PNODE list(int );
void show(PNODE ,int a[],int );
int a[2000000];
int main()
{
PNODE phead =NULL;
int n,m;
scanf("%d%d",&n,&m);
phead = list(n);
for(int i = 0 ; i < m;i++)
{
scanf("%d",&a[i]);
}
show(phead,a,m);
return 0;
}
PNODE list(int n)
{
int val;
PNODE phead = (PNODE)malloc(sizeof(NODE));
if(phead == NULL)
{
return 0;
}
PNODE ptail = phead;
if(ptail == NULL)return 0;
for(int i = 0 ; i < n ; i++)
{
PNODE pnew = (PNODE)malloc(sizeof(NODE));
if(pnew == NULL)return 0;
scanf("%d",&val);
pnew->data = val ;
ptail->next = pnew ;
pnew->next = NULL;
ptail = pnew;
}
return phead;
}
void show(PNODE phead,int a[],int m)
{
PNODE p=phead->next;
int k = 1,t=0;
while(t+1<=m)
{
if(k==a[t])
{
t++;
printf("%d\n",p->data);
p=p->next;
}
else
{
p=p->next;
}
k++;
}
}