#include <bits/stdc++.h>
using namespace std;
vector<int> t;
int n;
int sum(int r) {
  int ans = 0;
  for (; r >= 0; r = (r & (r + 1)) - 1) ans += t[r];
  return ans;
}
void inc(int i, int x) {
  for (; i < n; i = (i | (i + 1))) t[i] += x;
}
int main() {
  ios_base::sync_with_stdio(false);
  int q, type, x;
  cin >> n >> q;
  deque<pair<int, int> > d;
  vector<int> a(n, 0);
  t.resize(n, 0);
  int cnt = 0;
  vector<set<int> > pos(n);
  for (int i = 0; i < q; i++) {
    cin >> type >> x;
    if (type == 1) {
      inc(x - 1, 1);
      a[x - 1]++;
      pos[x - 1].insert(cnt + 1);
      cout << sum(n - 1) << endl;
      d.push_back(make_pair(cnt + 1, x - 1));
      cnt++;
      continue;
    }
    if (type == 3) {
      while (!d.empty() && d.front().first <= x) {
        int b = d.front().second;
        int p = d.front().first;
        if (a[b] && pos[b].count(p)) {
          a[b]--;
          inc(b, -1);
        }
        d.pop_front();
      }
      cout << sum(n - 1) << endl;
      continue;
    }
    if (type == 2) {
      pos[x - 1].clear();
      inc(x - 1, -a[x - 1]);
      a[x - 1] = 0;
      cout << sum(n - 1) << endl;
      continue;
    }
  }
  return 0;
}
