#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
const double inf = ~0u >> 2;
int s[100000 << 2];
int a[100000];
void up(int w) { s[w] = s[w << 1] + s[w << 1 | 1]; }
void build(int l, int r, int w) {
  if (l == r) {
    s[w] = a[l] = 1;
    return;
  }
  int m = (l + r) >> 1;
  build(l, m, w << 1);
  build(m + 1, r, w << 1 | 1);
  up(w);
}
void update(int p, int d, int l, int r, int w) {
  if (l == r) {
    s[w] += d;
    a[l] = s[w];
    return;
  }
  int m = (l + r) >> 1;
  if (p <= m)
    update(p, d, l, m, w << 1);
  else
    update(p, d, m + 1, r, w << 1 | 1);
  up(w);
}
int query(int a, int b, int l, int r, int w) {
  if (a <= l && b >= r) {
    return s[w];
  }
  int m = (l + r) >> 1;
  int res = 0;
  if (a <= m) res += query(a, b, l, m, w << 1);
  if (b > m) res += query(a, b, m + 1, r, w << 1 | 1);
  return res;
}
int main() {
  int n, m, i, j;
  cin >> n >> m;
  build(1, n, 1);
  int lef = 1, rig = n;
  while (m--) {
    int x, y, z;
    scanf("%d%d", &x, &y);
    if (x == 1) {
      int mid = (abs(rig - lef) + 1) >> 1;
      if (y > mid) {
        swap(lef, rig);
        y = abs(rig - lef) + 1 - y;
      }
      int st, en;
      if (lef < rig) {
        st = lef + y - 1;
        j = st + 1;
        for (i = st; i >= lef; i--) {
          update(j, a[i], 1, n, 1);
          j++;
        }
        lef = st + 1;
      } else {
        st = lef - y + 1;
        j = st - 1;
        for (i = st; i <= lef; i++) {
          update(j, a[i], 1, n, 1);
          j--;
        }
        lef = st - 1;
      }
    } else {
      scanf("%d", &z);
      y++;
      int ll, rr;
      if (lef > rig) {
        ll = lef - z + 1;
        rr = lef - y + 1;
      } else {
        ll = lef + y - 1;
        rr = lef + z - 1;
      }
      cout << query(ll, rr, 1, n, 1) << endl;
    }
  }
  return 0;
}
