#include <bits/stdc++.h>
using namespace std;
int ni() {
  int a;
  scanf("%d", &a);
  return a;
}
double nf() {
  double a;
  scanf("%lf", &a);
  return a;
}
char sbuf[100005];
string ns() {
  scanf("%s", sbuf);
  return sbuf;
}
long long nll() {
  long long a;
  scanf("%lld", &a);
  return a;
}
template <class T>
void out(T a, T b) {
  bool first = true;
  for (T i = a; i != b; ++i) {
    if (!first) printf(" ");
    first = false;
    cout << *i;
  }
  printf("\n");
}
template <class T>
void outl(T a, T b) {
  for (T i = a; i != b; ++i) {
    cout << *i << "\n";
  }
}
int n, m;
set<pair<int, int>> pq;
map<int, int> l2r, r2l;
map<int, int> emp;
vector<pair<int, pair<int, int>>> cmd;
const int maxt = 524300;
const int rright = 262144;
int t[maxt];
void addt(int pos, int add) {
  pos += rright;
  while (pos >= 1) {
    t[pos] += add;
    pos >>= 1;
  }
}
int gett(int pos) {
  pos += rright;
  int ret = 0;
  while (pos >= 1) {
    if (pos & 1) {
      ret += t[pos - 1];
    }
    pos >>= 1;
  }
  return ret;
}
int main() {
  int i, j, k;
  n = ni();
  m = ni();
  pq.insert(make_pair(-n, 0));
  l2r[0] = n;
  r2l[n] = 0;
  for (i = (0); i < (((m))); ++i) {
    int eId = ni();
    if (!eId) {
      int a = ni();
      --a;
      int b = ni();
      cmd.push_back(make_pair(1, make_pair(a, b)));
    } else {
      if (emp.find(eId) != emp.end()) {
        int pos = emp[eId];
        cmd.push_back(make_pair(0, make_pair(pos, -1)));
        int l = r2l[pos];
        int r = l2r[pos + 1];
        pq.erase(make_pair(-(pos - l), -(l)));
        pq.erase(make_pair(-(r - (pos + 1)), -(pos + 1)));
        pq.insert(make_pair(-(r - l), -(l)));
        r2l[r] = l;
        l2r[l] = r;
        emp.erase(eId);
      } else {
        pair<int, int> best = *pq.begin();
        pq.erase(best);
        int l = -best.second;
        int r = -best.second - best.first;
        int pos = (l + r) / 2;
        cmd.push_back(make_pair(0, make_pair(pos, 1)));
        emp[eId] = pos;
        pq.insert(make_pair(-(pos - l), -(l)));
        pq.insert(make_pair(-(r - (pos + 1)), -(pos + 1)));
        r2l[r] = pos + 1;
        l2r[pos + 1] = r;
        r2l[pos] = l;
        l2r[l] = pos;
      }
    }
  }
  vector<int> xs;
  map<int, int> mx;
  for (i = (0); i < (((cmd.size()))); ++i) {
    if (cmd[i].first) {
      xs.push_back(cmd[i].second.first);
      xs.push_back(cmd[i].second.second - 1);
    } else {
      xs.push_back(cmd[i].second.first);
    }
  }
  sort((xs).begin(), (xs).end());
  xs.resize(unique((xs).begin(), (xs).end()) - xs.begin());
  for (i = (0); i < (((xs.size()))); ++i) mx[xs[i]] = i;
  for (i = (0); i < (((cmd.size()))); ++i) {
    if (cmd[i].first) {
      cmd[i].second.first = mx[cmd[i].second.first];
      cmd[i].second.second = mx[cmd[i].second.second - 1] + 1;
    } else {
      cmd[i].second.first = mx[cmd[i].second.first];
    }
  }
  for (i = (0); i < (((cmd.size()))); ++i) {
    if (cmd[i].first) {
      printf("%d\n", gett(cmd[i].second.second) - gett(cmd[i].second.first));
    } else {
      addt(cmd[i].second.first, cmd[i].second.second);
    }
  }
  return 0;
}
