#include<iostream>#include<vector>constexprint MAX =10e5+1;int n, q;usingnamespace std;structChest{
vector<int>box, item;int num;}chest[MAX];intmain(){
cin >> n >> q;for(int i =0; i < q; i++){int a, b, c, d;
cin >> a;if(1== a){
cin >> b >> c >> d;
chest[b].num++;
chest[b].box.push_back(c);
chest[b].item.push_back(d);}elseif(2== a){
cin >> b >> c;for(int i = chest[b].num -1; i >=0; i--)if((chest[b].box)[i]== c &&(chest[b].item)[i]!=0){
cout <<(chest[b].item)[i]<< endl;break;}}}return0;}