#include <bits/stdc++.h>
using namespace std;
int A[(1 << 17)];
int A0[(1 << 17)];
int A1[(1 << 17)];
int C[(1 << 17)];
int RMQ[2 << 20];
int I[32];
void Add(int a, int b) {
  int i;
  for (i = (0); i < (20); ++i) RMQ[I[i] + (a >> i)] += b;
}
int Sum(int a) {
  int res = 0;
  int i;
  for (i = (0); i < (20); ++i) {
    if (a & 1) res += RMQ[I[i] + a - 1];
    a >>= 1;
  }
  return res;
}
int main() {
  int N, M;
  scanf("%d%d", &N, &M);
  vector<int> v;
  int i;
  for (i = (0); i < (M); ++i) {
    scanf("%d", &A[i]);
    if (A[i] == 0)
      scanf("%d%d", &A0[i], &A1[i]);
    else
      v.push_back(A[i]);
  }
  sort((v).begin(), (v).end());
  v.resize(unique((v).begin(), (v).end()) - v.begin());
  for (i = (0); i < (M); ++i)
    if (A[i] != 0)
      A[i] = int(lower_bound((v).begin(), (v).end(), A[i]) - v.begin()) + 1;
  set<pair<int, int> > bl, lb;
  bl.insert(pair<int, int>(-1, -N));
  lb.insert(pair<int, int>(-N, -1));
  v.clear();
  memset(C, -1, sizeof(C));
  for (i = (0); i < (M); ++i)
    if (A[i] != 0)
      if (C[A[i]] == -1) {
        pair<int, int> t = *lb.begin();
        lb.erase(lb.begin());
        bl.erase(pair<int, int>(t.second, t.first));
        int l = -t.second;
        int r = -t.second - t.first;
        int m = (l + r) / 2;
        bl.insert(pair<int, int>(-l, l - m));
        lb.insert(pair<int, int>(l - m, -l));
        bl.insert(pair<int, int>(-(m + 1), (m + 1) - r));
        lb.insert(pair<int, int>((m + 1) - r, -(m + 1)));
        A0[i] = m;
        C[A[i]] = m;
        v.push_back(m);
      } else {
        pair<int, int> t(-C[A[i]], 0);
        set<pair<int, int> >::iterator it0 = bl.lower_bound(t);
        set<pair<int, int> >::iterator it1 = it0;
        --it1;
        pair<int, int> r = *it1;
        pair<int, int> l = *it0;
        bl.erase(l);
        bl.erase(r);
        lb.erase(pair<int, int>(l.second, l.first));
        lb.erase(pair<int, int>(r.second, r.first));
        l.second += r.second - 1;
        bl.insert(l);
        lb.insert(pair<int, int>(l.second, l.first));
        A0[i] = -C[A[i]];
        C[A[i]] = -1;
      }
  for (i = (0); i < (M); ++i)
    if (A[i] == 0) {
      ++A1[i];
      v.push_back(A0[i]);
      v.push_back(A1[i]);
    }
  sort((v).begin(), (v).end());
  v.resize(unique((v).begin(), (v).end()) - v.begin());
  memset(RMQ, 0, sizeof(RMQ));
  I[0] = 0;
  for (i = (1); i < (20); ++i) I[i] = I[i - 1] + (1 << (21 - i));
  for (i = (0); i < (M); ++i)
    if (A[i] == 0) {
      A0[i] = lower_bound((v).begin(), (v).end(), A0[i]) - v.begin();
      A1[i] = lower_bound((v).begin(), (v).end(), A1[i]) - v.begin();
      printf("%d\n", Sum(A1[i]) - Sum(A0[i]));
    } else if (A0[i] < 0) {
      A0[i] = lower_bound((v).begin(), (v).end(), -A0[i]) - v.begin();
      Add(A0[i], -1);
    } else {
      A0[i] = lower_bound((v).begin(), (v).end(), A0[i]) - v.begin();
      Add(A0[i], 1);
    }
  return 0;
};
