#include <bits/stdc++.h>
using namespace std;
int N, M, b, e, ar[110000], size, seg[510000];
int init(int k, int b, int e) {
  if (b == e) return seg[k] = 1;
  return seg[k] = init(2 * k, b, ((b + e) / 2)) +
                  init(2 * k + 1, ((b + e) / 2) + 1, e);
}
int upd(int k, int b, int e, int a, int t) {
  if (b > a || e < a) return seg[k];
  if (b == e) return seg[k] = t;
  return seg[k] = upd(2 * k, b, ((b + e) / 2), a, t) +
                  upd(2 * k + 1, ((b + e) / 2) + 1, e, a, t);
}
int find(int k, int b, int e, int a1, int a2) {
  if (b > a2 || e < a1) return 0;
  if (a1 <= b && e <= a2) return seg[k];
  return find(2 * k, b, ((b + e) / 2), a1, a2) +
         find(2 * k + 1, ((b + e) / 2) + 1, e, a1, a2);
}
int main() {
  cin >> N >> M;
  b = 0, e = N, size = N + 1;
  int dir = 0;
  for (int i = 1; i <= N; i++) ar[i] = 1;
  init(1, 1, N);
  for (int z = 1, type, a, c; z <= M; z++) {
    scanf(" %d %d", &type, &a);
    if (type == 2) {
      scanf(" %d", &c);
      if (dir) {
        a = e - b - a;
        c = e - b - c;
        if (a > c) swap(a, c);
      }
      printf("%d\n", find(1, 1, N, b + a + 1, b + c));
    } else {
      if (dir == 0) {
        if (a <= size / 2) {
          for (int i = b + 1, j = b + a + a; i <= j; i++, j--) {
            ar[j] += ar[i];
            upd(1, 1, N, j, ar[j]);
          }
          b += a;
        } else {
          for (int i = e, j = e - (e - b - a) * 2 + 1; j <= i; j++, i--) {
            ar[j] += ar[i];
            upd(1, 1, N, j, ar[j]);
          }
          e = b + a;
          dir = !dir;
        }
      } else {
        if (a <= size / 2) {
          for (int i = e, j = e - a * 2 + 1; j <= i; j++, i--) {
            ar[j] += ar[i];
            upd(1, 1, N, j, ar[j]);
          }
          e -= a;
        } else {
          a = e - b - a;
          for (int i = b + 1, j = b + a + a; i <= j; i++, j--) {
            ar[j] += ar[i];
            upd(1, 1, N, j, ar[j]);
          }
          b += a;
          dir = !dir;
        }
      }
    }
    size = e - b + 1;
  }
  return 0;
}
