#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000000007;
const int maxn = 100000 + 10;
int sum[maxn << 2], cnt[maxn << 2], n, q;
void pushUp(int rt) { sum[rt] = sum[rt << 1] + sum[rt << 1 | 1]; }
void build(int l, int r, int rt) {
  cnt[rt] = 1;
  if (l == r) {
    sum[rt] = 1;
    return;
  }
  int m = (l + r) >> 1;
  build(l, m, rt << 1);
  build(m + 1, r, rt << 1 | 1);
  pushUp(rt);
}
int Find(int k, int l, int r, int rt) {
  if (l == r) return cnt[rt];
  int m = (l + r) >> 1;
  if (k <= m)
    return Find(k, l, m, rt << 1);
  else
    return Find(k, m + 1, r, rt << 1 | 1);
}
void Update(int k, int val, int l, int r, int rt) {
  if (l == r) {
    cnt[rt] += val;
    sum[rt] += val;
    return;
  }
  int m = (l + r) >> 1;
  if (k <= m)
    Update(k, val, l, m, rt << 1);
  else
    Update(k, val, m + 1, r, rt << 1 | 1);
  pushUp(rt);
}
void add(int l1, int r1, int l2, int r2) {
  int j = r1;
  for (int i = l2; i <= r2; i++) {
    int val = Find(j, 1, n, 1);
    Update(i, val, 1, n, 1);
    if (--j < l1) break;
  }
}
void add2(int l1, int r1, int l2, int r2) {
  int j = l1;
  for (int i = r2; i >= l2; i--) {
    int val = Find(j, 1, n, 1);
    Update(i, val, 1, n, 1);
    if (++j > r1) break;
  }
}
int Query(int L, int R, int l, int r, int rt) {
  if (L <= l && R >= r) {
    return sum[rt];
  }
  int m = (l + r) >> 1;
  int ret = 0;
  if (L <= m) ret += Query(L, R, l, m, rt << 1);
  if (R > m) ret += Query(L, R, m + 1, r, rt << 1 | 1);
  return ret;
}
int main() {
  cin >> n >> q;
  int L = 1, R = n;
  int cur = 0;
  build(1, n, 1);
  while (q--) {
    int op, l, r, p;
    scanf("%d", &op);
    if (op == 1) {
      scanf("%d", &p);
      if (p <= R - L + 1 - p) {
        if (!cur) {
          add(L, p + L - 1, p + L, 2 * p + L - 1);
          L += p;
        } else {
          add(R - p + 1, R, R - 2 * p + 1, R - p);
          R -= p;
        }
      } else if (cur) {
        p = R - L + 1 - p;
        add(L, L + p - 1, L + p, 2 * p + L - 1);
        L += p;
        cur = 0;
      } else {
        add2(L + p, R, L, L + p - 1);
        cur ^= 1;
        R = L + p - 1;
      }
    } else if (op == 2) {
      scanf("%d%d", &l, &r);
      if (cur) {
        printf("%d\n", Query(R - r + 1, R - l, 1, n, 1));
      } else {
        printf("%d\n", Query(L + l, L + r - 1, 1, n, 1));
      }
    }
  }
  return 0;
}
