#include <bits/stdc++.h>
using namespace std;
int a[100100];
int lowbit(int x) { return x & (-x); }
void add(int pos, int add) {
  int x = pos;
  while (x < 100100) {
    a[x] += add;
    x += lowbit(x);
  }
  return;
}
int sum(int x) {
  int res = 0;
  while (x) {
    res += a[x];
    x -= lowbit(x);
  }
  return res;
}
int N, Q;
int main() {
  while (~scanf("%d%d", &N, &Q)) {
    memset(a, 0, sizeof(a));
    for (int i = 1; i <= N; ++i) {
      add(i, 1);
    }
    int rev = 0;
    int st = 1, end = N;
    while (Q--) {
      int op;
      scanf("%d", &op);
      if (op == 1) {
        int p;
        scanf("%d", &p);
        if (rev == 0) {
          if (p <= (end - st + 1) / 2) {
            p += st - 1;
            for (int j = p; j >= st; --j) {
              add(2 * p - j + 1, sum(j) - sum(j - 1));
            }
            st = p + 1;
          } else {
            p += st - 1;
            for (int j = end; j >= p + 1; --j) {
              add(2 * p - j + 1, sum(j) - sum(j - 1));
            }
            end = p;
            rev = 1;
          }
        } else {
          if (p <= (end - st + 1) / 2) {
            p = end - p;
            for (int j = end; j >= p + 1; --j) {
              add(2 * p - j + 1, sum(j) - sum(j - 1));
            }
            end = p;
          } else {
            p = end - p;
            for (int j = p; j >= st; --j) {
              add(2 * p - j + 1, sum(j) - sum(j - 1));
            }
            st = p + 1;
            rev = 0;
          }
        }
      } else {
        int l, r;
        scanf("%d%d", &l, &r);
        if (rev) {
          l = end - l;
          r = end - r;
        } else {
          l += st - 1;
          r += st - 1;
        }
        if (l > r) swap(l, r);
        printf("%d\n", sum(r) - sum(l));
      }
    }
  }
  return 0;
}
