#include <bits/stdc++.h>
#pragma comment(linker, "/stack:16777216")
using namespace std;
const int INF = 1000000000;
const int MAX = 600007;
const int ADD = 300000;
const int MAX2 = 7000;
const int BASE = 1000000000;
int n, m;
int l, r;
int T[MAX * 4];
void Add(int j, int d, int i, int l, int r) {
  if (l == r)
    T[i] += d;
  else {
    int m = (l + r) / 2;
    if (j <= m)
      Add(j, d, i * 2, l, m);
    else
      Add(j, d, i * 2 + 1, m + 1, r);
    T[i] = T[i * 2] + T[i * 2 + 1];
  }
}
int Sum(int l, int r, int i, int tl, int tr) {
  if (l > r) return 0;
  if (l == tl && r == tr) return T[i];
  int m = (tl + tr) / 2;
  if (r <= m) return Sum(l, r, i * 2, tl, m);
  if (l > m) return Sum(l, r, i * 2 + 1, m + 1, tr);
  return Sum(l, m, i * 2, tl, m) + Sum(m + 1, r, i * 2 + 1, m + 1, tr);
}
int main() {
  scanf("%d %d", &n, &m);
  l = 0;
  r = n - 1;
  for (int i = (0); i < (n); ++i) Add(ADD + i, 1, 1, 0, MAX - 1);
  int cur = 0;
  for (int i = (0); i < (m); ++i) {
    int t, a, b;
    scanf("%d", &t);
    int len = r - l + 1;
    if (t == 1) {
      scanf("%d", &a);
      if (a * 2 > len) {
        cur ^= 1;
        a = len - a;
      }
      if (cur == 0) {
        int pos = l + 2 * a - 1;
        for (int j = (0); j < (a); ++j) {
          int val = Sum(ADD + l, ADD + l, 1, 0, MAX - 1);
          Add(ADD + pos, val, 1, 0, MAX - 1);
          Add(ADD + l, -val, 1, 0, MAX - 1);
          ++l;
          r = max(r, pos);
          --pos;
        }
      } else {
        int pos = r - 2 * a + 1;
        for (int j = (0); j < (a); ++j) {
          int val = Sum(ADD + r, ADD + r, 1, 0, MAX - 1);
          Add(ADD + pos, val, 1, 0, MAX - 1);
          Add(ADD + r, -val, 1, 0, MAX - 1);
          --r;
          l = min(l, pos);
          ++pos;
        }
      }
    } else {
      scanf("%d %d", &a, &b);
      int aa = a, bb = b;
      if (cur == 0) {
        a = l + aa;
        b = l + bb - 1;
      } else if (cur == 1) {
        a = r - bb + 1;
        b = r - aa;
      }
      printf("%d\n", Sum(ADD + a, ADD + b, 1, 0, MAX - 1));
    }
  }
  return 0;
}
