#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long INF = 4e18;
const int inf = 2e9;
const int N = 1e5 + 10;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
long long bit[N];
int n;
void add(int pos, long long add) {
  for (; pos <= n; pos |= pos + 1) bit[pos] += add;
}
long long find(int pos) {
  long long ret = 0;
  for (; pos >= 0; pos = (pos & (pos + 1)) - 1) ret += bit[pos];
  return ret;
}
int main(void) {
  int q, i;
  scanf("%d %d", &n, &q);
  for (i = 1; i <= n; ++i) add(i, 1);
  int shift = 0, len = n;
  bool st = 0;
  while (q--) {
    int type, p, l, r;
    scanf("%d", &type);
    if (type == 1) {
      scanf("%d", &p);
      int rev = len - shift - p;
      if (st == 0) {
        if (p <= rev) {
          for (i = 1; i <= p; ++i) {
            long long move = find(shift + p + 1 - i) - find(shift + p - i);
            add(shift + p + i, move);
          }
          shift += p;
        } else {
          for (i = 1; i <= rev; ++i) {
            long long move = find(shift + p + i) - find(shift + p + i - 1);
            add(shift + p + 1 - i, move);
          }
          len -= rev;
          st ^= 1;
        }
      } else {
        if (p <= rev) {
          for (i = 1; i <= p; ++i) {
            long long move = find(shift + rev + i) - find(shift + rev + i - 1);
            add(shift + rev + 1 - i, move);
          }
          len -= p;
        } else {
          for (i = 1; i <= rev; ++i) {
            long long move = find(shift + rev + 1 - i) - find(shift + rev - i);
            add(shift + rev + i, move);
          }
          shift += rev;
          st ^= 1;
        }
      }
    } else {
      scanf("%d %d", &l, &r);
      if (st == 0)
        printf("%I64d\n", find(shift + r) - find(shift + l));
      else {
        printf("%I64d\n", find(len - l) - find(len - r));
      }
    }
  }
  return 0;
}
