#include using namespace std; using ll=long long; #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() template bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;} template bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;} int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N,Q; cin>>N>>Q; set>A,B; mapmp; vectorans; while(Q--){ int t; cin>>t; if(t==1){ string s; int r; cin>>s>>r; mp[s]=r; A.insert(make_pair(r,s)); }else if(t==2){ int x; cin>>x; N-=x; }else{ string s; int x; cin>>s>>x; N+=x; if(A.count(make_pair(mp[s],s))){ A.erase(make_pair(mp[s],s)); B.insert(make_pair(mp[s],s)); } } while((int)A.size()+(int)B.size()>N){ if(A.size()){ auto id=A.begin(); ans.push_back((*id).second); A.erase(id); }else{ auto id=B.begin(); ans.push_back((*id).second); B.erase(id); } } } cout<<(int)ans.size()<<"\n"; for(auto s:ans)cout<