#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000001;
const double EPS = 10e-9;
int const S = 1 << 17;
int gdziezero, curlen;
bool ifflipped;
int tree[2 * S];
int Read(int p) {
  if (ifflipped)
    p = gdziezero - p;
  else
    p = gdziezero + p;
  return tree[p];
}
void Set(int p, int vl) {
  if (ifflipped)
    p = gdziezero - p;
  else
    p = gdziezero + p;
  for (tree[p] += vl, p >>= 1; p; p >>= 1)
    tree[p] = tree[2 * p] + tree[2 * p + 1];
}
int Sum(int l, int r) {
  if (ifflipped) {
    int tmp = l;
    l = gdziezero - r;
    r = gdziezero - tmp;
  } else {
    l = gdziezero + l;
    r = gdziezero + r;
  }
  int s = l;
  int j = 1;
  int sum = 0;
  while (l <= r) {
    while (!(l & 1) && (s + j) <= r) {
      s += j;
      j <<= 1;
      l >>= 1;
    }
    sum += tree[l];
    ++s;
    l = s;
    j = 1;
  }
  return sum;
}
int main() {
  int n, q, zap, l, r;
  cin >> n >> q;
  gdziezero = S;
  curlen = n;
  for (int i = 1; i <= (n); ++i) Set(i, 1);
  for (int i = 0; i < (q); ++i) {
    cin >> zap;
    if (zap == 1) {
      cin >> l;
      if (2 * l > curlen) {
        for (int j = l + 1; j <= (curlen); ++j) Set(2 * l + 1 - j, Read(j));
        if (ifflipped)
          gdziezero -= l + 1;
        else
          gdziezero += l + 1;
        ifflipped ^= true;
        curlen -= (curlen - l);
      } else {
        for (int j = 1; j <= (l); ++j) Set(2 * l + 1 - j, Read(j));
        for (int j = 1; j <= (l); ++j) Set(j, -Read(j));
        if (ifflipped)
          gdziezero -= l;
        else
          gdziezero += l;
        curlen -= l;
      }
    } else {
      cin >> l >> r;
      cout << Sum(l + 1, r) << endl;
    }
  }
  return 0;
}
