#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 105000;
const int p = 1000000007;
int dat[4 * MAX_N - 1], n, q;
void init(int n_) {
  n = 1;
  while (n < n_) n *= 2;
  for (int i = 0; i < 2 * n - 1; i++) dat[i] = 0;
}
void update(int k, int x) {
  k += n - 1;
  dat[k] += x;
  while (k > 0) {
    k = (k - 1) / 2;
    dat[k] = dat[2 * k + 1] + dat[2 * k + 2];
  }
}
int sum(int a, int b, int k, int l, int r) {
  if (b < l || r < a) return 0;
  if (a <= l && r <= b)
    return dat[k];
  else {
    int v1 = sum(a, b, 2 * k + 1, l, (l + r) / 2);
    int v2 = sum(a, b, 2 * k + 2, (l + r) / 2 + 1, r);
    return v1 + v2;
  }
}
int main() {
  int kind, l, r, head, tail, m, cur;
  scanf("%d%d", &m, &q);
  n = m;
  init(n);
  for (int i = 0; i < m; i++) update(i, 1);
  head = 0;
  tail = m - 1;
  cur = 0;
  while (q--) {
    scanf("%d", &kind);
    if (kind == 1) {
      scanf("%d", &l);
      if (2 * l <= tail - head + 1) {
        if (cur == 0) {
          head += l;
          for (int i = 0; i < l; i++)
            update(head + i, dat[head - i - 1 + n - 1]);
        } else {
          tail -= l;
          for (int i = 0; i < l; i++) update(tail - i, dat[tail + i + n]);
        }
      } else {
        cur ^= 1;
        l = (tail - head + 1) - l;
        if (cur == 0) {
          head += l;
          for (int i = 0; i < l; i++)
            update(head + i, dat[head - i - 1 + n - 1]);
        } else {
          tail -= l;
          for (int i = 0; i < l; i++) update(tail - i, dat[tail + i + n]);
        }
      }
    } else {
      scanf("%d%d", &l, &r);
      if (cur == 0)
        printf("%d\n", sum(head + l, head + r - 1, 0, 0, n - 1));
      else
        printf("%d\n", sum(tail - r + 1, tail - l, 0, 0, n - 1));
    }
  }
  return 0;
}
