#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Element
{
struct Element *next;
int u,key;
};
struct Element* InitSingleLinkedList()
{
struct Element *list;
list = (struct Element*)malloc(sizeof(struct Element));
list->next=NULL;
list->u=-999999;
list->key=-999999;
return list;
}
void InsertAfter(struct Element* list, struct Element* y)
{
struct Element* x,*z;
for (x=list; x!=NULL;)
{
z=x;
x=x->next;
}
z->next=y;
y->next=NULL;
}
void Assign(struct Element **AM,int k,int u,int m,struct Element *new)
{
struct Element *check;
int h=k%m;
if(AM[h]->next!=AM[h])
{
for(check = AM[h]->next; check != NULL && k!=check->key; check=check->next);
if(check==NULL)
{
new->u=u;
new->key=k;
InsertAfter(AM[h],new);
}
else
{
check->u=u;
}
}
else
{
new->u=u;
new->key=k;
InsertAfter(AM[h],new);
}
new=NULL;
free(new);
}
void AT(struct Element **AM,int k,int m)
{
int h=k%m;
struct Element *find;
for (find=AM[h]->next;find!=NULL && k!=find->key;find=find->next);
if (find==NULL)
{
printf("0\n");
}
else
{
printf("%d\n",find->u);
}
}
int main (int argc, char const *argv[])
{
int n,m,k=0,El=0,i;
struct Element **AM;
struct Element *freee;
struct Element *next;
char str[6];
scanf("%d", &n);
scanf("%d", &m);
AM = malloc(m * sizeof(struct Element*));
for(i = 0; i < m;i++)
{
AM[i]=InitSingleLinkedList();
}
for(i = 0; i < n; i++)
{
scanf("%s",str);
scanf("%d",&k );
if(str[2]=='\0')
{
AT(AM,k,m);
}
else
{
freee=InitSingleLinkedList();
scanf("%d",&El );
Assign(AM,k,El,m,freee);
}
}
for (i=0;i<m;i++)
{
for (freee=AM[i];freee!=NULL;)
{
next=freee->next;
free(freee);
freee=next;
AM[i]=freee;
}
}
free(AM);
return 0;
}