#include <bits/stdc++.h>
using namespace std;
long long tree[100005];
int n;
void update(int idx, int val) {
  if (idx == 0) return;
  while (idx <= n) {
    tree[idx] += val;
    idx += (idx & -idx);
  }
}
long long sum(int idx) {
  if (idx <= 0) return 0;
  long long res = 0;
  while (idx > 0) {
    res += tree[idx];
    idx -= (idx & -idx);
  }
  return res;
}
int a[100005];
int main() {
  int q, type, x, y, l, r;
  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    a[i] = 1;
    update(i, 1);
  }
  l = 1;
  r = n;
  int dir = 1;
  for (int i = 0; i < q; i++) {
    cin >> type;
    if (type == 1) {
      cin >> x;
      int ptr1, ptr2;
      if (dir) {
        if (2 * x <= (r - l + 1)) {
          ptr1 = l + x;
          ptr2 = l + x - 1;
          for (; ptr2 >= l; ptr2--) {
            a[ptr1] += a[ptr2];
            update(ptr1, a[ptr2]);
            update(ptr2, -a[ptr2]);
            a[ptr2] = 0;
            ptr1++;
          }
          l += x;
        } else {
          x = r - l + 1 - x;
          ptr1 = r - x;
          ptr2 = r - x + 1;
          for (; ptr2 <= r; ptr2++) {
            a[ptr1] += a[ptr2];
            update(ptr1, a[ptr2]);
            update(ptr2, -a[ptr2]);
            a[ptr2] = 0;
            ptr1--;
          }
          r -= x;
          dir = 0;
        }
      } else {
        if (2 * x <= (r - l + 1)) {
          ptr1 = r - x;
          ptr2 = r - x + 1;
          for (; ptr2 <= r; ptr2++) {
            a[ptr1] += a[ptr2];
            update(ptr1, a[ptr2]);
            update(ptr2, -a[ptr2]);
            a[ptr2] = 0;
            ptr1--;
          }
          r -= x;
        } else {
          x = r - l + 1 - x;
          ptr1 = l + x;
          ptr2 = l + x - 1;
          for (; ptr2 >= l; ptr2--) {
            a[ptr1] += a[ptr2];
            update(ptr1, a[ptr2]);
            update(ptr2, -a[ptr2]);
            a[ptr2] = 0;
            ptr1++;
          }
          l += x;
          dir = 1;
        }
      }
    } else {
      cin >> x >> y;
      if (dir) {
        x = x + l - 1;
        y = y + l - 1;
        cout << sum(y) - sum(x) << "\n";
      } else {
        x = r - x;
        y = r - y;
        cout << sum(x) - sum(y) << "\n";
      }
    }
  }
  return 0;
}
