#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 20;
int n, m, l, r, data[4 * maxn], nex, pre, type, index__, cur, now, ne, pointer;
vector<pair<int, pair<int, int> > > vc;
vector<int> hlp;
void add(int p, int val, int st = 0, int en = hlp.size(), int id = 1) {
  data[id] += val;
  if (en - st < 2) return;
  int mid = (st + en) >> 1;
  if (p < mid) return add(p, val, st, mid, id << 1);
  return add(p, val, mid, en, id << 1 ^ 1);
}
int get(int l, int r, int st = 0, int en = hlp.size(), int id = 1) {
  if (r <= st || en <= l) return 0;
  if (l <= st && en <= r) return data[id];
  int mid = (st + en) >> 1;
  return get(l, r, st, mid, id << 1) + get(l, r, mid, en, id << 1 ^ 1);
}
set<int> salam;
set<pair<int, int> > ST;
map<int, int> len, ind, chn;
map<int, bool> is_in;
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  ST.insert(pair<int, int>(-n, -(n + 1)));
  salam.insert(n + 1);
  len[n + 1] = n;
  while (m--) {
    cin >> type;
    if (type) {
      if (is_in[type]) {
        is_in[type] = false;
        index__ = ind[type];
        nex = *(salam.upper_bound(index__)++);
        ST.erase(pair<int, int>(-len[nex], -nex));
        ST.erase(pair<int, int>(-len[index__], -index__));
        len[nex] += len[index__] + 1;
        ST.insert(pair<int, int>(-len[nex], -nex));
        vc.push_back(make_pair(0, pair<int, int>(index__, -1)));
        salam.erase(index__);
      } else {
        now = ST.begin()->first;
        cur = ST.begin()->second;
        now *= -1;
        cur *= -1;
        ne = cur - ((now + 1) / 2);
        is_in[type] = 1;
        ind[type] = ne;
        ST.erase(ST.begin());
        len[ne] = now / 2;
        len[cur] = now - (now / 2) - 1;
        salam.insert(ne);
        ST.insert(pair<int, int>(-len[cur], -cur));
        ST.insert(pair<int, int>(-len[ne], -ne));
        vc.push_back(make_pair(0, pair<int, int>(ne, +1)));
        hlp.push_back(ne);
      }
    } else {
      cin >> l >> r;
      r++;
      vc.push_back(make_pair(1, pair<int, int>(l, r)));
      hlp.push_back(l);
      hlp.push_back(r);
    }
  }
  for (int i = 0; i < vc.size(); i++)
    if (vc[i].first == 0)
      hlp.push_back(vc[i].second.first);
    else
      hlp.push_back(vc[i].second.first), hlp.push_back(vc[i].second.second);
  sort(hlp.begin(), hlp.end());
  hlp.resize(unique(hlp.begin(), hlp.end()) - hlp.begin());
  for (int i = 0; i < vc.size(); i++)
    if (vc[i].first == 0)
      add(lower_bound(hlp.begin(), hlp.end(), vc[i].second.first) - hlp.begin(),
          vc[i].second.second);
    else
      printf("%d\n",
             get(lower_bound(hlp.begin(), hlp.end(), vc[i].second.first) -
                     hlp.begin(),
                 lower_bound(hlp.begin(), hlp.end(), vc[i].second.second) -
                     hlp.begin()));
}
