#include <bits/stdc++.h>
using namespace std;
int n, q;
int l, r;
int rec[105000];
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 0; i <= n; i++) {
    rec[i] = i;
  }
  l = 0;
  r = n;
  bool ok = false;
  for (int i = 1; i <= q; i++) {
    int jj;
    scanf("%d", &jj);
    if (jj == 1) {
      int p;
      scanf("%d", &p);
      if (!ok) {
        if (p * 2 > (r - l)) {
          ok = true;
          int f = p + l;
          int sum = 0;
          for (int j = r; j > f; j--) {
            sum += rec[j] - rec[j - 1];
            rec[2 * f - j + 1] += sum;
          }
          r = f;
        } else {
          int f = p + l;
          int sum = 0;
          for (int j = f; j >= l + 1; j--) {
            sum += rec[j] - rec[j - 1];
            rec[2 * f - j + 1] += (sum - rec[f]);
          }
          rec[f] = 0;
          l = f;
        }
      } else {
        if (p * 2 > (r - l)) {
          ok = false;
          int f = r - p;
          int sum = 0;
          for (int j = f; j >= l + 1; j--) {
            sum += rec[j] - rec[j - 1];
            rec[2 * f - j + 1] += (sum - rec[f]);
          }
          rec[f] = 0;
          l = f;
        } else {
          int f = r - p;
          int sum = 0;
          for (int j = r; j > f; j--) {
            sum += rec[j] - rec[j - 1];
            rec[2 * f - j + 1] += sum;
          }
          r = f;
        }
      }
    } else {
      int ll, rr;
      scanf("%d%d", &ll, &rr);
      if (!ok) {
        int sum = 0;
        sum = rec[l + rr] - rec[l + ll];
        printf("%d\n", sum);
      } else {
        int sum = 0;
        sum = rec[r - ll] - rec[r - rr];
        printf("%d\n", sum);
      }
    }
  }
  return 0;
}
