#include <bits/stdc++.h>
using namespace std;
int n, m, l, r, sl, q;
int a[200005];
int c[200005];
void jia(int x, int y) {
  while (x <= n) {
    c[x] += y;
    x += (x & (-x));
  }
}
int he(int x) {
  int ans = 0;
  while (x > 0) {
    ans += c[x];
    x -= (x & (-x));
  }
  return ans;
}
int qiu(int l, int r) { return he(r) - he(l - 1); }
void orz(int x, int y) {
  a[x] += y;
  jia(x, y);
}
void zzq(int x) {
  for (int i = l; i < x; i++) {
    orz(x * 2 - i - 1, a[i]);
  }
  l = x;
}
void wxh(int x) {
  for (int i = r; i >= x; i--) {
    orz(x * 2 - i - 1, a[i]);
  }
  r = x - 1;
}
int o = 0;
inline int QAQ(int x) {
  if (o == 1) return l + r - x;
  return x;
}
int main() {
  cin >> n >> q;
  l = 1;
  r = n;
  sl = 1;
  for (int i = 1; i <= n; i++) orz(i, 1);
  for (int i = 1; i <= q; i++) {
    int opt;
    cin >> opt;
    sl = l;
    if (opt == 1) {
      int x;
      cin >> x;
      x += sl;
      sl = l;
      if (o == 0) {
        if (x * 2 > (l + r)) {
          wxh(x);
          o ^= 1;
        } else {
          zzq(x);
        }
      } else {
        x = (r + l - x);
        x++;
        if (x * 2 > (l + r)) {
          wxh(x);
        } else {
          zzq(x);
          o ^= 1;
        }
      }
    } else {
      int ll, rr;
      cin >> ll >> rr;
      ll += sl;
      rr += sl;
      rr--;
      ll = QAQ(ll);
      rr = QAQ(rr);
      if (rr < ll) swap(ll, rr);
      cout << qiu(ll, rr) << "\n";
    }
  }
  return 0;
}
