#include <bits/stdc++.h>
using namespace std;
int tree[100005];
int n;
void gao(int x, int y) {
  while (x <= n) {
    tree[x] += y;
    x += (x & (-x));
  }
}
int qu(int x) {
  int y = 0;
  while (x) {
    y += tree[x];
    x -= (x & (-x));
  }
  return y;
}
int cao, b, e, w;
int wei(int i) {
  if (cao == 0) {
    return b + i;
  } else
    return b - i + 1;
}
int main() {
  int ca;
  cin >> n >> ca;
  b = 0;
  e = n;
  w = e - b;
  cao = 0;
  for (int i = 1; i <= n; i++) gao(i, 1);
  for (int gg = 1; gg <= ca; gg++) {
    int flag;
    cin >> flag;
    if (flag == 1) {
      int q;
      cin >> q;
      if (q * 2 <= w) {
        for (int i = 1; i <= q; i++) {
          int x = wei(2 * q + 1 - i);
          int y = wei(i);
          gao(x, qu(y) - qu(y - 1));
        }
        if (cao == 0) {
          b = b + q;
          w = w - q;
        } else {
          b -= q;
          w -= q;
        }
      } else {
        for (int i = q + 1; i <= w; i++) {
          int x = wei(i);
          int y = wei(q + 1 - (i - q));
          gao(y, qu(x) - qu(x - 1));
        }
        if (cao == 0) {
          cao = 1;
          int rt = e;
          e = b;
          b = rt - (w - q);
          w -= w - q;
        } else {
          int rt = e;
          cao = 0;
          e = b;
          b = rt + (w - q);
          w -= w - q;
        }
      }
    } else {
      int l, r;
      cin >> l >> r;
      if (cao == 0) {
        int x = wei(l);
        int y = wei(r);
        cout << qu(y) - qu(x) << endl;
      } else {
        int x = b - l;
        int y = b - r;
        cout << qu(x) - qu(y) << endl;
      }
    }
  }
  return 0;
}
