#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > ev;
int cnt[1000100], MX;
void add(int a, int v) {
  while (a <= MX) {
    cnt[a] += v;
    a += (a & (-a));
  }
}
int get(int a) {
  int res = 0;
  while (a > 0) {
    res += cnt[a];
    a -= (a & (-a));
  }
  return res;
}
int main(void) {
  int n;
  int q;
  scanf("%d%d", &n, &q);
  set<pair<int, int>, greater<pair<int, int> > > S;
  map<int, int> cur;
  set<int> zaj;
  S.insert(make_pair(n, 1));
  zaj.insert(0);
  zaj.insert(n + 1);
  for (int i = 0; i < (q); ++i) {
    int x;
    scanf("%d", &x);
    if (x == 0) {
      int a, b;
      scanf("%d%d", &a, &b);
      ev.push_back(make_pair(a, b));
    } else {
      if (cur.find(x) == cur.end()) {
        int len = S.begin()->first;
        int y = S.begin()->second;
        int mid = y + (len / 2);
        S.erase(S.begin());
        if (mid > y) S.insert(make_pair(mid - y, y));
        if (mid < y + len - 1) S.insert(make_pair(y + len - 1 - mid, mid + 1));
        ev.push_back(make_pair(0, mid));
        cur[x] = mid;
        zaj.insert(mid);
      } else {
        int g = cur[x];
        ev.push_back(make_pair(-1, g));
        set<int>::iterator it = zaj.find(g), jt = it, kt = it;
        --jt;
        ++kt;
        if (*jt < g - 1) S.erase(make_pair(g - (*jt + 1), *jt + 1));
        if (*kt > g + 1) S.erase(make_pair((*kt) - g - 1, g + 1));
        S.insert(make_pair((*kt) - (*jt) - 1, (*jt) + 1));
        zaj.erase(g);
        cur.erase(x);
      }
    }
  }
  map<int, int> ma;
  for (int i = 0; i < (((int)((ev).size()))); ++i) {
    if (ev[i].first > 0) ma[ev[i].first] = 1;
    ma[ev[i].second] = 1;
  }
  int M = 1;
  for (__typeof((ma).begin()) it = (ma).begin(); it != (ma).end(); ++it)
    ma[it->first] = M++;
  MX = M + 1;
  for (int i = 0; i < (((int)((ev).size()))); ++i) {
    if (ev[i].first == 0)
      add(ma[ev[i].second], 1);
    else if (ev[i].first == -1)
      add(ma[ev[i].second], -1);
    else
      printf("%d\n", get(ma[ev[i].second]) - get(ma[ev[i].first] - 1));
  }
  return 0;
}
