#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1e5;
int t[4 * maxn];
void build(int it, int l, int r) {
  if (l == r) {
    t[it] = 1;
  } else {
    int m = (l + r) / 2;
    build(2 * it, l, m);
    build(2 * it + 1, m + 1, r);
    t[it] = t[2 * it] + t[2 * it + 1];
  }
}
int search(int it, int l, int r, int lm, int rm) {
  if (l == lm && r == rm) {
    return t[it];
  } else {
    int m = (l + r) / 2;
    if (rm <= m) {
      return search(2 * it, l, m, lm, rm);
    } else if (lm > m) {
      return search(2 * it + 1, m + 1, r, lm, rm);
    } else {
      return search(2 * it, l, m, lm, m) +
             search(2 * it + 1, m + 1, r, m + 1, rm);
    }
  }
}
void change(int it, int l, int r, int pos, int x) {
  if (l == r) {
    t[it] += x;
  } else {
    int m = (l + r) / 2;
    if (pos <= m) {
      change(2 * it, l, m, pos, x);
    } else {
      change(2 * it + 1, m + 1, r, pos, x);
    }
    t[it] = t[2 * it] + t[2 * it + 1];
  }
}
int main() {
  int n, q;
  scanf("%d %d", &n, &q);
  build(1, 0, n - 1);
  int l = 0, r = n - 1;
  int len = n;
  for (int i = 0; i < q; i++) {
    int t;
    scanf("%d", &t);
    if (t == 1) {
      int x;
      scanf("%d", &x);
      if (l <= r) {
        if (2 * x <= len) {
          len -= x;
          int now = l + x - 1;
          for (int j = l + x; j < l + 2 * x; j++) {
            change(1, 0, n - 1, j, search(1, 0, n - 1, now, now));
            now--;
          }
          l += x;
        } else {
          x = len - x;
          len -= x;
          swap(l, r);
          int now = l - x + 1;
          for (int j = l - x; j > l - 2 * x; j--) {
            change(1, 0, n - 1, j, search(1, 0, n - 1, now, now));
            now++;
          }
          l -= x;
        }
      } else {
        if (2 * x <= len) {
          len -= x;
          int now = l - x + 1;
          for (int j = l - x; j > l - 2 * x; j--) {
            change(1, 0, n - 1, j, search(1, 0, n - 1, now, now));
            now++;
          }
          l -= x;
        } else {
          x = len - x;
          len -= x;
          swap(l, r);
          int now = l + x - 1;
          for (int j = l + x; j < l + 2 * x; j++) {
            change(1, 0, n - 1, j, search(1, 0, n - 1, now, now));
            now--;
          }
          l += x;
        }
      }
    } else {
      int x, y;
      scanf("%d %d", &x, &y);
      y--;
      if (l <= r) {
        x += l;
        y += l;
        printf("%d\n", search(1, 0, n - 1, x, y));
      } else {
        x = l - x;
        y = l - y;
        printf("%d\n", search(1, 0, n - 1, y, x));
      }
    }
  }
  return 0;
}
