#include <bits/stdc++.h>
using namespace std;
int n, q, fl;
map<int, int> m, l, r, sot, kol;
set<int> kor;
set<pair<int, pair<int, int> > > s;
vector<pair<int, int> > zpr;
int sum[800100];
void inc(int p, int z) {
  for (; p < fl; p = (p | (p + 1))) sum[p] += z;
}
int otr(int p) {
  int tek = 0;
  for (; p > 0; p = (p & (p + 1)) - 1) tek += sum[p];
  return tek;
}
int main() {
  scanf("%d%d", &n, &q);
  s.insert(make_pair(n, make_pair(0, n + 1)));
  kor.insert(0);
  kor.insert(n + 1);
  l[0] = n + 1;
  r[n + 1] = 0;
  set<pair<int, pair<int, int> > >::iterator it;
  for (int i = 1; i <= q; i++) {
    int x, y;
    scanf("%d", &x);
    if (x == 0) {
      scanf("%d%d", &x, &y);
      kor.insert(x);
      kor.insert(y);
      zpr.push_back(make_pair(x, y));
    } else {
      zpr.push_back(make_pair(x, 0));
      kol[x]++;
      if (kol[x] % 2 == 1) {
        it = s.end();
        it--;
        int le = (*it).first, pos;
        pos = (*it).second.first + le / 2 + 1;
        kor.insert(pos);
        int st = (*it).second.first, fin = (*it).second.second;
        l[st] = pos;
        r[fin] = pos;
        r[pos] = st;
        l[pos] = fin;
        sot[x] = pos;
        s.erase(it);
        s.insert(make_pair(pos - st - 1, make_pair(st, pos)));
        s.insert(make_pair(fin - pos - 1, make_pair(pos, fin)));
      } else {
        int st, fin, pos;
        pos = sot[x];
        st = r[pos];
        fin = l[pos];
        l[st] = fin;
        r[fin] = st;
        s.erase(make_pair(pos - st - 1, make_pair(st, pos)));
        s.erase(make_pair(fin - pos - 1, make_pair(pos, fin)));
        s.insert(make_pair(fin - st - 1, make_pair(st, fin)));
      }
    }
  }
  sot.clear();
  kol.clear();
  s.clear();
  l.clear();
  r.clear();
  fl = 0;
  for (set<int>::iterator it = kor.begin(); it != kor.end(); it++) {
    m[*it] = fl;
    fl++;
  }
  s.insert(make_pair(n, make_pair(0, n + 1)));
  kor.insert(0);
  kor.insert(n + 1);
  l[0] = n + 1;
  r[n + 1] = 0;
  for (int i = 0; i < q; i++) {
    int x, y;
    if (zpr[i].second != 0) {
      int ll = m[zpr[i].first], rr = m[zpr[i].second];
      printf("%d\n", otr(rr) - otr(ll - 1));
    } else {
      x = zpr[i].first;
      kol[x]++;
      if (kol[x] % 2 == 1) {
        it = s.end();
        it--;
        int le = (*it).first, pos;
        pos = (*it).second.first + le / 2 + 1;
        kor.insert(pos);
        int st = (*it).second.first, fin = (*it).second.second;
        l[st] = pos;
        r[fin] = pos;
        r[pos] = st;
        l[pos] = fin;
        sot[x] = pos;
        s.erase(it);
        s.insert(make_pair(pos - st - 1, make_pair(st, pos)));
        s.insert(make_pair(fin - pos - 1, make_pair(pos, fin)));
        inc(m[pos], 1);
      } else {
        int st, fin, pos;
        pos = sot[x];
        st = r[pos];
        fin = l[pos];
        l[st] = fin;
        r[fin] = st;
        s.erase(make_pair(pos - st - 1, make_pair(st, pos)));
        s.erase(make_pair(fin - pos - 1, make_pair(pos, fin)));
        s.insert(make_pair(fin - st - 1, make_pair(st, fin)));
        inc(m[pos], -1);
      }
    }
  }
}
