#include <bits/stdc++.h>
using namespace std;
int n, q;
long long st[300001];
long long brr[100001];
void updateValue(int ss, int se, int i, long long val, int index) {
  if (i < ss || i > se) return;
  st[index] = st[index] + val;
  if (se != ss) {
    int mid = ss + (se - ss) / 2;
    updateValue(ss, mid, i, val, 2 * index + 1);
    updateValue(mid + 1, se, i, val, 2 * index + 2);
  }
}
long long getSum(int ss, int se, int qs, int qe, int index) {
  if (qs <= ss && qe >= se) return st[index];
  if (se < qs || ss > qe) return 0;
  int mid = ss + (se - ss) / 2;
  return (long long)getSum(ss, mid, qs, qe, 2 * index + 1) +
         (long long)getSum(mid + 1, se, qs, qe, 2 * index + 2);
}
int constructST(int ss, int se, int si) {
  if (ss == se) {
    st[si] = brr[ss];
    return st[si];
  }
  int mid = ss + (se - ss) / 2;
  int left = constructST(ss, mid, si * 2 + 1);
  int right = constructST(mid + 1, se, si * 2 + 2);
  st[si] = left + right;
  return st[si];
}
int main() {
  cin >> n >> q;
  for (int i = 0; i < 100001; i++) brr[i] = 1;
  constructST(0, n - 1, 0);
  long long ans = 0;
  int s = 0, e = n - 1;
  for (int qq = 0; qq < q; qq++) {
    int qe;
    cin >> qe;
    if (qe == 1) {
      int p;
      cin >> p;
      if (s == e) continue;
      if (s < e) {
        if (p <= (e - s + 1) / 2) {
          int j = s + p;
          for (int i = s + p - 1; i >= s; i--) {
            updateValue(0, n - 1, j, brr[i], 0);
            brr[j] += brr[i];
            j++;
          }
          s = s + p;
        } else {
          p = e - s + 1 - p;
          int j = e - p;
          for (int i = e - p + 1; i <= e; i++) {
            updateValue(0, n - 1, j, brr[i], 0);
            brr[j] += brr[i];
            j--;
          }
          e = e - p;
          swap(s, e);
        }
      } else {
        if (p <= (s - e + 1) / 2) {
          int j = s - p;
          for (int i = s - p + 1; i <= s; i++) {
            updateValue(0, n - 1, j, brr[i], 0);
            brr[j] += brr[i];
            j--;
          }
          s = s - p;
        } else {
          p = s - e + 1 - p;
          int j = e + p;
          for (int i = e + p - 1; i >= e; i--) {
            updateValue(0, n - 1, j, brr[i], 0);
            brr[j] += brr[i];
            j++;
          }
          e = e + p;
          swap(s, e);
        }
      }
    } else {
      int l, r;
      cin >> l >> r;
      r--;
      if (s <= e) {
        l = l + s;
        r = r + s;
        cout << getSum(0, n - 1, l, r, 0) << endl;
      } else {
        l = s - l;
        r = s - r;
        cout << getSum(0, n - 1, r, l, 0) << endl;
      }
    }
  }
  return 0;
}
