#include <bits/stdc++.h>
using namespace std;
const int N = 64e5 + 10;
int id[N], len[N], len1[N], len2[N], tot, son[N][2], sum[N];
int init(int l, int r) {
  son[tot][0] = son[tot][1] = -1;
  len1[tot] = len2[tot] = len[tot] = r - l + 1;
  id[tot] = l;
  sum[tot] = r - l + 1;
  return tot++;
}
void pushup(int l, int r, int o) {
  if (len1[son[o][0]] == (l + r) / 2 - l + 1) {
    len1[o] = len1[son[o][0]] + len1[son[o][1]];
  } else
    len1[o] = len1[son[o][0]];
  if (len2[son[o][1]] == r - (l + r) / 2) {
    len2[o] = len2[son[o][1]] + len2[son[o][0]];
  } else
    len2[o] = len2[son[o][1]];
  len[o] = len[son[o][1]];
  id[o] = id[son[o][1]];
  if (len2[son[o][0]] + len1[son[o][1]] > len[o]) {
    len[o] = len2[son[o][0]] + len1[son[o][1]];
    id[o] = (l + r) / 2 - len2[son[o][0]] + 1;
  }
  if (len[son[o][0]] > len[o]) {
    len[o] = len[son[o][0]];
    id[o] = id[son[o][0]];
  }
  sum[o] = sum[son[o][0]] + sum[son[o][1]];
}
void pushdown(int l, int r, int o) {
  if (son[o][0] == -1) son[o][0] = init(l, (l + r) / 2);
  if (son[o][1] == -1) son[o][1] = init((l + r) / 2 + 1, r);
}
void update(int l, int r, int o, int x, int v) {
  if (l == r) {
    sum[o] = len1[o] = len2[o] = len[o] = v;
    id[o] = l;
    return;
  }
  pushdown(l, r, o);
  if (x <= (l + r) / 2) {
    update(l, (l + r) / 2, son[o][0], x, v);
  } else {
    update((l + r) / 2 + 1, r, son[o][1], x, v);
  }
  pushup(l, r, o);
}
int ans = 0, L, R;
void query(int l, int r, int o) {
  if (L <= l && r <= R) {
    ans += sum[o];
    return;
  }
  if (L <= (l + r) / 2) {
    if (son[o][0] != -1)
      query(l, (l + r) / 2, son[o][0]);
    else
      ans += min((l + r) / 2, R) - max(L, l) + 1;
  }
  if (R > (l + r) / 2) {
    if (son[o][1] != -1)
      query((l + r) / 2 + 1, r, son[o][1]);
    else
      ans += min(r, R) - max(L, (l + r) / 2 + 1) + 1;
  }
}
map<int, int> id_mp, num_mp;
int main() {
  int n, q;
  while (scanf("%d%d", &n, &q) != EOF) {
    id_mp.clear();
    num_mp.clear();
    tot = 0;
    init(1, n);
    for (int i = 0; i < q; i++) {
      int op, l, r;
      scanf("%d", &op);
      if (!op) {
        scanf("%d%d", &L, &R);
        ans = 0;
        query(1, n, 0);
        printf("%d\n", R - L + 1 - ans);
      } else {
        int x = num_mp[op];
        x++;
        if (x % 2 == 1) {
          id_mp[op] = id[0] + len[0] / 2;
          update(1, n, 0, id_mp[op], 0);
        } else {
          update(1, n, 0, id_mp[op], 1);
        }
        num_mp[op] = x;
      }
    }
  }
  return 0;
}
