#include <bits/stdc++.h>
using namespace std;
int n, m, a[500005], l = 1, r, b[500005];
queue<int> Q;
bool flag = false;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) a[i] = i & -i;
  for (int i = 1; i <= n; ++i) b[i] = 1;
  r = n;
  while (m--) {
    int opt, x, y;
    scanf("%d", &opt);
    if (opt == 1) {
      scanf("%d", &x);
      if (flag)
        x = r - x + 1;
      else
        x += l;
      if (r - x + 1 > x - l)
        while (l < x) {
          int tmp = 0;
          for (int j = l; j; j -= j & -j) tmp += a[j];
          for (int j = l - 1; j; j -= j & -j) tmp -= a[j];
          for (int j = l; j <= n; j += j & -j) a[j] -= tmp;
          b[x + x - l - 1] += b[l];
          b[l] = 0;
          for (int j = x + x - l - 1; j <= n; j += j & -j) a[j] += tmp;
          l++;
          flag = false;
        }
      else
        while (r >= x) {
          for (int i = x; i <= r; ++i) {
            int tmp = 0;
            for (int j = i; j; j -= j & -j) tmp += a[j];
            for (int j = i - 1; j; j -= j & -j) tmp -= a[j];
            for (int j = i; j <= n; j += j & -j) a[j] -= tmp;
            b[i] = 0;
            Q.push(tmp);
          }
          for (int i = x - 1; i >= x - (r - x + 1); --i) {
            int tmp = Q.front();
            Q.pop();
            for (int j = i; j <= n; j += j & -j) a[j] += tmp;
            b[i] += tmp;
          }
          r = x - 1;
          flag = true;
        }
    }
    if (opt == 2) {
      scanf("%d%d", &x, &y);
      int xx, yy;
      if (flag) {
        xx = r - y;
        yy = r - x;
        x = xx, y = yy;
      } else
        x = x + l - 1, y = y + l - 1;
      int ans = 0;
      for (int j = y; j; j -= j & -j) ans += a[j];
      for (int j = x; j; j -= j & -j) ans -= a[j];
      printf("%d\n", ans);
    }
  }
}
