#include <bits/stdc++.h>
using namespace std;
const int maxn = 300010;
const int inf = 1e9 + 7;
set<pair<int, int> > S;
vector<int> G[maxn];
int start[maxn];
int main() {
  int n, q;
  while (~scanf("%d%d", &n, &q)) {
    S.clear();
    for (int i = 1; i <= n; i++) {
      G[i].clear();
    }
    int idx = 0;
    for (int i = 1, t, x; i <= q; i++) {
      scanf("%d%d", &t, &x);
      if (t == 1) {
        idx++;
        S.insert(pair<int, int>(idx, x));
        G[x].push_back(idx);
      } else if (t == 2) {
        for (int i = start[x]; i < G[x].size(); i++) {
          int u = G[x][i];
          S.erase(pair<int, int>(u, x));
        }
        G[x].clear();
        start[x] = 0;
      } else {
        vector<pair<int, int> > vs;
        set<pair<int, int> >::iterator ite =
            S.upper_bound(pair<int, int>(x, inf));
        if (ite != S.begin()) {
          --ite;
          while (ite != S.begin()) {
            pair<int, int> p = *ite;
            start[p.second]++;
            vs.push_back(p);
            --ite;
          }
          pair<int, int> p = *ite;
          start[p.second]++;
          vs.push_back(p);
          for (auto u : vs) {
            S.erase(u);
          }
        }
      }
      cout << S.size() << endl;
    }
  }
  return 0;
}
