#include <bits/stdc++.h>
using namespace std;
const int maxn = 300001;
int f[maxn], a[maxn];
inline void add(int x, int val) {
  for (int i = x + 1; i < maxn; i += i & (-i)) f[i] += val;
}
inline int get(int x) {
  int ans = 0;
  for (int i = x; i > 0; i -= i & (-i)) ans += f[i];
  return ans;
}
inline int sum(int x, int y) { return get(y) - get(x); }
int main() {
  int q, l, r, n, m, rev = 0;
  scanf("%d%d", &n, &m);
  int cr = n - 1, cl = 0;
  int len = cr - cl + 1;
  for (int i = 0; i < n; ++i) add(i, a[i] = 1);
  for (int t = 0; t < m; ++t) {
    scanf("%d", &q);
    if (q == 1) {
      scanf("%d", &l);
      if (l > len - l) rev ^= 1, l = len - l;
      if (rev) {
        cr = cr - l;
        for (int i = cr; i >= cr - l + 1; --i)
          add(i, a[2 * cr - i + 1]), a[i] += a[2 * cr - i + 1];
      } else {
        cl = cl + l;
        for (int i = cl; i <= cl + l - 1; ++i)
          add(i, a[2 * cl - i - 1]), a[i] += a[2 * cl - i - 1];
      }
      len = cr - cl + 1;
    }
    if (q == 2) {
      scanf("%d%d", &l, &r);
      int ln = (r - l);
      if (rev)
        l = cr - l + 1, r = l - ln, swap(l, r);
      else
        l += cl, r += cl;
      printf("%d\n", sum(l, r));
    }
  }
}
