#include <bits/stdc++.h>
using namespace std;
long long seg[600010], lazy[600010];
int N, Q;
inline void lazy_eval(int k) {
  if (lazy[k]) {
    seg[k * 2 + 1] += lazy[k];
    seg[k * 2 + 2] += lazy[k];
    lazy[k * 2 + 1] += lazy[k];
    lazy[k * 2 + 2] += lazy[k];
    lazy[k] = 0;
  }
}
void update(int a, int x, int k = 0, int l = 0, int r = N) {
  int b = a + 1;
  if (b <= l || r <= a) return;
  lazy_eval(k);
  if (a <= l && r <= b) {
    seg[k] += x;
    lazy[k] += x;
  } else {
    update(a, x, k * 2 + 1, l, (l + r) / 2);
    update(a, x, k * 2 + 2, (l + r) / 2, r);
    seg[k] = seg[k * 2 + 1] + seg[k * 2 + 2];
  }
}
long long sum(int a, int b, int k = 0, int l = 0, int r = N) {
  if (b <= l || r <= a) return 0;
  lazy_eval(k);
  if (a <= l && r <= b) {
    return seg[k];
  }
  long long lv = sum(a, b, k * 2 + 1, l, (l + r) / 2);
  long long rv = sum(a, b, k * 2 + 2, (l + r) / 2, r);
  return lv + rv;
}
int main() {
  scanf("%d%d", &N, &Q);
  for (int i = 0; i < N; i++) {
    update(i, 1);
  }
  int at = 0, len = N;
  bool flip = false;
  while (Q--) {
    int type;
    scanf("%d", &type);
    if (type == 1) {
      int m;
      scanf("%d", &m);
      if (!flip) {
        if (m <= len / 2) {
          for (int i = 0; i < m; i++) {
            update(at + m + i, sum(at + m - i - 1, at + m - i));
          }
          at += m;
          len -= m;
        } else {
          for (int i = 0; i < len - m; i++) {
            update(at + m - 1 - i, sum(at + m + i, at + m + i + 1));
          }
          flip = true;
          len -= len - m;
        }
      } else {
        if (m <= len / 2) {
          for (int i = 0; i < m; i++) {
            update(at + len - m - 1 - i,
                   sum(at + len - m + i, at + len - m + i + 1));
          }
          len -= m;
        } else {
          for (int i = 0; i < len - m; i++) {
            update(at + len - m + i,
                   sum(at + len - m - 1 - i, at + len - m - i));
          }
          flip = false;
          at += len - m;
          len -= len - m;
        }
      }
    } else {
      int l, r;
      scanf("%d %d", &l, &r);
      if (!flip) {
        printf("%I64d\n", sum(at + l, at + r));
      } else {
        printf("%I64d\n", sum(at + len - r, at + len - l));
      }
    }
  }
}
