#include <bits/stdc++.h>
using namespace std;
const double eps = 1E-9;
const double Exp = 2.718281828459045;
const double Pi = 3.1415926535897932;
const int Max_Bit = 63;
const int INF = 2000000000;
const long long LINF = 1000000000000000007ll;
const int MOD = 1000000007;
const int NMAX = 100005;
const int MMAX = 305;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
const string CODE = "CODEFORCES";
int n, sum[NMAX];
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
void update(int x, int c) {
  ++x;
  while (x <= n) {
    sum[x] += c;
    x += x & -x;
  }
}
int query(int x) {
  int second = 0;
  while (x) {
    second += sum[x];
    x -= x & -x;
  }
  return second;
}
int main() {
  int l, r, p, q, ff, cnt[NMAX], rev = 0, x, y;
  scanf("%d%d", &n, &q);
  l = 0;
  r = n;
  for (int i = 0; i < n; ++i) {
    cnt[i] = 1;
    update(i, 1);
  }
  for (int j = 0; j < q; ++j) {
    scanf("%d", &ff);
    if (ff - 1) {
      scanf("%d%d", &x, &y);
      if (rev) {
        int tmp = x;
        x = r - l - y;
        y = r - l - tmp;
      }
      printf("%d\n", query(y + l) - query(x + l));
    } else {
      scanf("%d", &p);
      if (rev) rev = 0, p = r - l - p;
      if (l + 2 * p <= r) {
        for (int i = 0; i < p; ++i) {
          int u = cnt[l + p - i - 1];
          cnt[l + p - i - 1] = 0;
          update(l + p - i - 1, -u);
          cnt[l + p + i] += u;
          update(l + p + i, u);
        }
        l = l + p;
      } else {
        for (int i = 0; i < r - l - p; ++i) {
          int u = cnt[l + p + i];
          cnt[l + p + i] = 0;
          update(l + p + i, -u);
          cnt[l + p - i - 1] += u;
          update(l + p - i - 1, u);
        }
        r = l + p;
        rev ^= 1;
      }
    }
  }
}
