/*1.start coding at 2024-04-27 17:29
1.stop coding at 2024-04-27 18:10
The reason is "class begin"
finish coding at 2024-04-27 17:57
2.start coding at 2024-05-07 17:33
2.stop coding at 2024-05-07 17:50
The reason is "Big cleaning"
3.start coding at 2024-05-13 17:18
3.stop coding at 2024-05-13 17:50
4.start coding at 2024-05-14 17:40
4.stop coding at 2024-05-14 18:??
The reason is "class begin"
finish debuging at 2024-05-?? ??:??
Code by 5520qq
虽千万人逆我之我仍执着
侠客行遍九州恩仇奔波
刀光剑影里是谁的明眸粲粲如星火
纵使我双掌倚天苍龙俘获
奈何降不住这人心如魔
所谓天下第一怎囿(拘泥;局限。如:囿于成见)我天高海阔
此即 智慧之殿堂!
*/
#include<bits/stdc++.h>
using namespace std;
struct node{int x,last,next;}f[100001];
int n,m,t,a[100001],y,h=-1,e;
string s;
int main(){
cin>>n>>m;
for(int i=0;i<n;i++)cin>>a[i];
cin>>t;
f[0].next=-1,f[0].last=-1;
while(t--){
cin>>s;
if(s=="push"){
cin>>y;
int i;
for(i=h;i!=-1;i=f[i].next){
if(f[i].last==-1||a[f[f[i].last].x]==a[y]&&a[f[f[i].next].x]!=a[y])break;
}if(h==-1)f[++e].last=-1,f[e].x=y,f[e].next=-1,h=e;//当列表为空的加入方法。
else f[++e].last=i,f[e].x=y,f[e].next=f[i].next,f[i].next=e;//列表不空的加入方法。
}else cout<<f[h].x<<endl,f[f[h].next].last=-1,h=f[h].next;
// cout<<"now:";
// for(int i=h;i!=-1;i=f[i].next)cout<<f[i].x<<' ';
// cout<<endl;
}
return 0;
}