#include <bits/stdc++.h>
using namespace std;
int N = 1 << 19;
vector<int> p(2 * N, 0);
int summa(int a, int b) {
  a += N;
  b += N;
  int s = 0;
  while (a <= b) {
    if (a % 2 == 1) s += p[a++];
    if (b % 2 == 0) s += p[b--];
    a /= 2;
    b /= 2;
  }
  return s;
}
void muuta(int k, int x) {
  k += N;
  p[k] = x;
  for (k /= 2; k >= 1; k /= 2) {
    p[k] = p[2 * k] + p[2 * k + 1];
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  int curnotes = 0;
  map<int, vector<int>> appToIdx;
  set<int> unread;
  while (q--) {
    int type;
    cin >> type;
    if (type == 1) {
      int x;
      cin >> x;
      appToIdx[x].emplace_back(curnotes);
      unread.insert(curnotes);
      curnotes++;
      cout << curnotes - summa(0, curnotes - 1) << "\n";
    } else if (type == 2) {
      int x;
      cin >> x;
      for (auto a : appToIdx[x]) {
        muuta(a, 1);
        if (unread.count(a)) {
          unread.erase(a);
        }
      }
      appToIdx[x].clear();
      cout << curnotes - summa(0, curnotes - 1) << "\n";
    } else {
      int t;
      cin >> t;
      int i = t - 1;
      while (!unread.empty() && *unread.begin() < t) {
        muuta(*unread.begin(), 1);
        unread.erase(*unread.begin());
      }
      cout << curnotes - summa(0, curnotes - 1) << "\n";
    }
  }
}
