#include <bits/stdc++.h>
using namespace std;
long long bit[108000];
void add(long long pos, long long val) {
  pos++;
  while (pos < 108000) {
    bit[pos] += val;
    pos += pos & -pos;
  }
}
long long _sum(long long pos) {
  long long res = 0;
  pos++;
  while (pos) {
    res += bit[pos];
    pos -= pos & -pos;
  }
  return res;
}
long long sum(long long l, long long r) {
  l--, r--;
  return _sum(r) - _sum(l);
}
long long val(long long pos) { return _sum(pos) - _sum(pos - 1); }
int main() {
  long long n, q, p, l, r, op;
  scanf("%lld%lld", &n, &q);
  long long flip = 0;
  long long nowleft = 0;
  long long nowright = n - 1;
  for (long long i = 0; i < n; i++) {
    add(i, 1);
  }
  for (long long i = 0; i < q; i++) {
    scanf("%lld", &op);
    if (op == 1) {
      scanf("%lld", &p);
      if (p <= (nowright - nowleft + 1) / 2) {
        if (flip) {
          for (long long j = nowright - p + 1; j <= nowright; j++) {
            add(nowright - p + 1 - j + nowright - p, val(j));
          }
          nowright = nowright - p;
        } else {
          for (long long j = nowleft + p - 1; j >= nowleft; j--) {
            add(nowleft + p - 1 - j + nowleft + p, val(j));
          }
          nowleft = nowleft + p;
        }
      } else {
        p = (nowright - nowleft + 1) - p;
        flip ^= 1;
        if (flip) {
          for (long long j = nowright - p + 1; j <= nowright; j++) {
            add(nowright - p + 1 - j + nowright - p, val(j));
          }
          nowright = nowright - p;
        } else {
          for (long long j = nowleft + p - 1; j >= nowleft; j--) {
            add(nowleft + p - 1 - j + nowleft + p, val(j));
          }
          nowleft = nowleft + p;
        }
      }
    } else {
      scanf("%lld%lld", &l, &r);
      if (flip) {
        printf("%lld\n", sum(nowright - r + 1, nowright - l + 1));
      } else {
        printf("%lld\n", sum(nowleft + l, nowleft + r));
      }
    }
  }
  return 0;
}
