#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 5;
struct BIT {
  int a[N], n;
  void Init(int n) {
    this->n = n;
    memset(a, 0, sizeof(a));
    return;
  }
  void add(int p, int v) {
    for (p = p + 1; p <= n; p += p & -p) {
      a[p] += v;
    }
    return;
  }
  int query(int p) {
    int res = 0;
    for (p = p + 1; p > 0; p -= p & -p) res += a[p];
    return res;
  }
};
int f[N];
int main() {
  int n, q;
  cin >> n >> q;
  BIT *TA = new BIT();
  TA->Init(n);
  for (int i = 0; i < n; i++) {
    f[i] = 1;
    TA->add(i, 1);
  }
  int s = 0, l = 0, r = n;
  for (int i = 0; i < q; i++) {
    int x;
    cin >> x;
    if (x == 1) {
      int p;
      cin >> p;
      if (p + p <= r - l) {
        if (s == 0) {
          for (int i = l; i < l + p; i++) {
            f[2 * (l + p) - 1 - i] += f[i];
            TA->add(2 * (l + p) - 1 - i, f[i]);
          }
          l += p;
        } else {
          for (int i = r - p; i < r; i++) {
            f[2 * (r - p) - 1 - i] += f[i];
            TA->add(2 * (r - p) - 1 - i, f[i]);
          }
          r -= p;
        }
      } else {
        if (s == 0) {
          for (int i = l + p; i < r; i++) {
            f[2 * (l + p) - 1 - i] += f[i];
            TA->add(2 * (l + p) - 1 - i, f[i]);
          }
          r -= r - l - p;
        } else {
          for (int i = l; i < r - p; i++) {
            f[2 * (r - p) - 1 - i] += f[i];
            TA->add(2 * (r - p) - 1 - i, f[i]);
          }
          l += r - l - p;
        }
        s = s ^ 1;
      }
    } else {
      int a, b;
      cin >> a >> b;
      if (s == 0)
        printf("%d\n", TA->query(l + b - 1) - TA->query(l + a - 1));
      else
        printf("%d\n", -(TA->query(r - b - 1) - TA->query(r - a - 1)));
    }
  }
  return 0;
}
