#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
map<int, int> BIT;
int n, q;
inline int LB(int x) { return x & -x; }
void I(int x, int val) {
  for (int i = x; i <= n; i += i & (-i)) BIT[i] += val;
}
int Q(int x) {
  int res = 0;
  for (int i = x; i >= 1; i -= i & (-i))
    if (BIT.find(i) != BIT.end()) res += BIT[i];
  return (res);
}
map<int, int> pos, per;
map<pair<int, int>, int> inv;
int main() {
  cin >> n >> q;
  pos[0] = pos[n + 1] = 1;
  inv[make_pair(-n, -1)] = 1;
  for (int i = 0; i < q; ++i) {
    int kind;
    scanf("%d", &kind);
    if (0 == kind) {
      int l, r;
      scanf("%d%d", &l, &r);
      printf("%d\n", Q(r) - Q(l - 1));
    } else {
      int x = kind;
      if (per.find(x) == per.end()) {
        map<pair<int, int>, int>::iterator it = inv.begin();
        int length = -(it->first).first, start = -(it->first).second;
        inv.erase(it);
        pair<int, int> left, right;
        if (length & 1)
          left = make_pair(-length / 2, -start),
          right = make_pair(-length / 2, -(start + length / 2 + 1));
        else
          left = make_pair(-length / 2, -start),
          right = make_pair(-length / 2 + 1, -(start + length / 2 + 1));
        if (length == 2)
          inv[left] = 1;
        else if (length > 1)
          inv[left] = 1, inv[right] = 1;
        per[x] = start + length / 2;
        pos[start + length / 2] = 1;
        I(start + length / 2, 1);
      } else {
        map<int, int>::iterator it = per.find(x);
        int where = it->second;
        per.erase(it);
        int beg, len;
        it = pos.find(where);
        --it;
        beg = it->first + 1;
        if (beg < where) inv.erase(inv.find(make_pair(-where + beg, -beg)));
        it = pos.find(where);
        ++it;
        len = it->first - beg;
        if (where + 1 < it->first)
          inv.erase(inv.find(make_pair(-(it->first - where - 1), -where - 1)));
        pos.erase(pos.find(where));
        inv[make_pair(-len, -beg)] = 1;
        I(where, -1);
      }
    }
  }
  return 0;
}
