#include <bits/stdc++.h>
using namespace std;
const double pi = 3.1415926535897932384626433832795;
const double eps = 1e-8;
char ch[1 << 20];
string gs() {
  scanf("%s", ch);
  return string(ch);
}
string gl() {
  gets(ch);
  return string(ch);
}
template <class T>
T gcd(T a, T b) {
  return (!a) ? b : gcd(b % a, a);
}
void error() {
  int yyy = 0;
  cout << 7 / yyy;
}
set<pair<pair<int, int>, int> > Q;
map<int, pair<int, int> > P;
set<pair<int, int> > O;
vector<int> waspos;
int F[1 << 20];
void Fadd(int x, int v) {
  x += 10;
  while (x < 1 << 20) {
    F[x] += v;
    x += x & -x;
  }
}
int Fsum(int x) {
  x += 10;
  int r = 0;
  while (x) {
    r += F[x];
    x -= x & -x;
  }
  return r;
}
int Fsum(int a, int b) { return Fsum(b) - Fsum(a - 1); }
int WORK = 0;
void Qadd(int x) {
  set<pair<pair<int, int>, int> >::iterator it = --Q.end();
  int v = (it->first.first) / 2 + 1;
  int mid = it->first.second + v;
  P[x] = make_pair(it->first.first - v, mid);
  Q.insert(make_pair(P[x], x));
  O.insert(make_pair(P[x].second, x));
  if (WORK) {
    Fadd(
        lower_bound(waspos.begin(), waspos.end(), P[x].second) - waspos.begin(),
        1);
  } else {
    waspos.push_back(P[x].second);
  }
  int nl = (it->first.first / 2);
  int y = it->second;
  int p = P[y].second;
  P[y] = make_pair(nl, p);
  Q.erase(it);
  Q.insert(make_pair(P[y], y));
}
void Qdel(int x) {
  int pos = P[x].second;
  int len = P[x].first;
  set<pair<int, int> >::iterator it = O.find(make_pair(pos, x));
  --it;
  int y = it->second;
  Q.erase(make_pair(P[y], y));
  Q.erase(make_pair(P[x], x));
  P[y].first += len + 1;
  Q.insert(make_pair(P[y], y));
  if (WORK) {
    Fadd(lower_bound(waspos.begin(), waspos.end(), pos) - waspos.begin(), -1);
  }
  O.erase(make_pair(pos, x));
  P.erase(x);
}
int Qsum(int a, int b) { return 0; }
int OP[1000000];
int A[1000000];
int B[1000000];
set<int> was;
void init(int n) {
  Q.clear();
  O.clear();
  P.clear();
  P[1 << 30] = make_pair(n, 0);
  O.insert(make_pair(0, 1 << 30));
  Q.insert(make_pair(P[1 << 30], 1 << 30));
}
int main(int argn, char **argv) {
  for (int i = (0), _b(10); i < _b; ++i) waspos.push_back(i);
  int n, q;
  scanf("%d%d", &n, &q);
  init(n);
  for (int i = (0), _b(q); i < _b; ++i) {
    int o;
    scanf("%d", &o);
    if (o == 0) {
      OP[i] = 2;
      scanf("%d%d", A + i, B + i);
    } else {
      if (was.count(o)) {
        OP[i] = 1, A[i] = o, Qdel(o);
        was.erase(o);
      } else {
        was.insert(o);
        OP[i] = 0, A[i] = o;
        Qadd(o);
      }
    }
  }
  sort(waspos.begin(), waspos.end());
  waspos.erase(unique(waspos.begin(), waspos.end()), waspos.end());
  WORK = 1;
  memset(F, 0, sizeof(F));
  init(n);
  for (int i = (0), _b(q); i < _b; ++i) {
    if (OP[i] == 0) {
      Qadd(A[i]);
    } else if (OP[i] == 1) {
      Qdel(A[i]);
    } else {
      int a = lower_bound(waspos.begin(), waspos.end(), A[i]) - waspos.begin();
      int j = lower_bound(waspos.begin(), waspos.end(), B[i]) - waspos.begin();
      if (j == waspos.size()) --j;
      if (waspos[j] > B[i]) --j;
      int r = Fsum(a, j);
      if (r < 0) r = 0;
      printf("%d\n", r);
    }
  }
  return 0;
}
