#include <bits/stdc++.h>
using namespace std;
int bit[100010];
int l[100010], r[100010];
map<int, int> ps;
int rp[100010];
int n, q;
vector<int> val;
int query(int x) {
  int ans = 0;
  for (int i = x; i; i -= (i & -i)) ans += bit[i];
  return ans;
}
void update(int x, int value) {
  for (int i = x; i <= val.size(); i += (i & -i)) bit[i] += value;
}
int main() {
  scanf("%d%d", &n, &q);
  set<pair<int, int>, greater<pair<int, int> > > s;
  set<int> sps;
  s.insert(make_pair(n, 1));
  sps.insert(0);
  sps.insert(n + 1);
  for (int i = 0; i < q; ++i) {
    int tag;
    scanf("%d", &tag);
    if (tag == 0) {
      scanf("%d%d", &l[i], &r[i]);
    } else {
      if (!ps[tag]) {
        int len = (*s.begin()).first;
        int st = (*s.begin()).second;
        s.erase(s.begin());
        int p = st + (len >> 1);
        rp[i] = ps[tag] = p;
        val.push_back(p);
        sps.insert(p);
        if (st < p) s.insert(make_pair(p - st, st));
        if (p < st + len - 1) s.insert(make_pair(st + len - p - 1, p + 1));
      } else {
        int p = ps[tag];
        ps[tag] = 0;
        rp[i] = -p;
        set<int>::iterator it, itl, itr;
        it = sps.find(p);
        itl = --it;
        ++it;
        itr = ++it;
        int lft = *itl;
        if (p - 1 > lft) s.erase(make_pair(p - lft - 1, lft + 1));
        int rgt = *itr;
        if (p + 1 < rgt) s.erase(make_pair(rgt - p - 1, p + 1));
        s.insert(make_pair(rgt - lft - 1, lft + 1));
        sps.erase(p);
      }
    }
  }
  sort(val.begin(), val.end());
  unique(val.begin(), val.end());
  for (int i = 0; i < q; ++i) {
    if (l[i]) {
      int pl = lower_bound(val.begin(), val.end(), l[i]) - val.begin() + 1;
      int pr = upper_bound(val.begin(), val.end(), r[i]) - val.begin();
      printf("%d\n", query(pr) - query(pl - 1));
    } else {
      int pos =
          lower_bound(val.begin(), val.end(), abs(rp[i])) - val.begin() + 1;
      if (rp[i] > 0)
        update(pos, 1);
      else
        update(pos, -1);
    }
  }
  return 0;
}
