#include <bits/stdc++.h>
using namespace std;
int sgn(double x) { return (x > 1e-8) - (x < -1e-8); }
int count_bit(int x) { return x == 0 ? 0 : count_bit(x >> 1) + (x & 1); }
template <class T>
inline void ckmin(T& a, const T b) {
  if (b < a) a = b;
}
template <class T>
inline void ckmax(T& a, const T b) {
  if (b > a) a = b;
}
const int MAXN = 100000 + 10;
struct binary_indexed_tree {
  int a[MAXN], val[MAXN];
  void clear() {
    memset(a, 0, sizeof(a));
    memset(val, 0, sizeof(val));
  }
  void update(int x, int y) {
    val[x] += y;
    for (; x < MAXN; x += ((x) & (-(x)))) {
      a[x] += y;
    }
  }
  int getsum(int x) {
    int ret = 0;
    for (; x; x -= ((x) & (-(x)))) {
      ret += a[x];
    }
    return ret;
  }
  int getsum(int l, int r) {
    int ret = 0;
    while (l <= r) {
      if (r - ((r) & (-(r))) + 1 >= l) {
        ret += a[r];
        r -= ((r) & (-(r)));
      } else {
        ret += val[r--];
      }
    }
    return ret;
  }
} bit;
void filp_left(int& l, int& r, int len) {
  for (int i = (1); i <= (len); ++i) {
    bit.update(l + len + len - i, bit.val[l + i - 1]);
  }
  l += len;
}
void filp_right(int& l, int& r, int len) {
  for (int i = (1); i <= (len); ++i) {
    bit.update(r - len - len + i, bit.val[r - i + 1]);
  }
  r -= len;
}
int main() {
  int n, q;
  while (scanf("%d%d", &n, &q) != EOF) {
    bit.clear();
    for (int i = 0; i < (n); ++i) {
      bit.update(i + 1, 1);
    }
    int off = 0;
    int l = 1, r = n;
    bool rev = false;
    for (int i = 0; i < (q); ++i) {
      int optype, flen, cl, cr;
      scanf("%d", &optype);
      if (optype == 1) {
        scanf("%d", &flen);
        int clen = r - l + 1;
        if (2 * flen > clen) {
          if (!rev) {
            filp_right(l, r, clen - flen);
          } else {
            filp_left(l, r, clen - flen);
          }
          rev = !rev;
        } else {
          if (!rev) {
            filp_left(l, r, flen);
          } else {
            filp_right(l, r, flen);
          }
        }
      } else {
        scanf("%d%d", &cl, &cr);
        int ret;
        if (!rev) {
          ret = bit.getsum(l + cl, l + cr - 1);
        } else {
          ret = bit.getsum(r - cr + 1, r - cl);
        }
        printf("%d\n", ret);
      }
    }
  }
  return 0;
}
