#include <bits/stdc++.h>
using namespace std;
const int imod = 1e9 + 7;
const long long lmod = 1e18 + 7;
const int iinf = INT_MAX;
const long long linf = LONG_MAX;
const double pi = 2 * acos(0.0);
const double eps = 1e-7;
const int N = 300100;
int n, q;
int cnt = 1, id = 1, ans;
set<int> s[N];
int par[N];
vector<int> v;
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> q;
  for (int ii = 1; ii <= q; ++ii) {
    int type, x;
    cin >> type >> x;
    if (type == 1) {
      s[x].insert(cnt);
      par[cnt] = x;
      cnt++;
      ans++;
      v.push_back(ans);
    }
    if (type == 2) {
      ans -= (int)s[x].size();
      s[x].clear();
      v.push_back(ans);
    }
    if (type == 3) {
      if (id > x) {
        v.push_back(ans);
        continue;
      }
      for (int i = id; i <= x; ++i) {
        int j = par[i];
        if (s[j].count(i) != 0) {
          ans--;
          s[j].erase(i);
        }
      }
      id = x + 1;
      v.push_back(ans);
    }
  }
  for (int i = 0; i < (int)v.size(); ++i) cout << v[i] << endl;
  return 0;
}
