#include <bits/stdc++.h>
const int INF = 1e9;
const int N = 312312;
const double PI = 3.1415926535897932384626433832795;
using namespace std;
int a[N], t[N], n, q;
int cl, cr;
bool rot;
void update(int x, int val) {
  for (; x <= n; x = (x | (x + 1))) t[x] += val;
}
int get(int x) {
  int res = 0;
  for (; x > 0; x = (x & (x + 1)) - 1) {
    res += t[x];
  }
  return res;
}
int get(int l, int r) { return get(r) - get(l - 1); }
void solve(int len, bool &rot) {
  int cur = cr - cl;
  if (rot) {
    len = cur - len;
  }
  if (len <= cur - len) {
    for (int i = cl + len, j = cl + len - 1; j >= cl; j--, i++) {
      int val = a[j];
      a[i] += val;
      update(i, val);
    }
    cl += len;
    if (rot) {
      rot = false;
    }
  } else {
    for (int i = cl + len, j = cl + len - 1; i < cr; j--, i++) {
      int val = a[i];
      a[j] += val;
      update(j, val);
    }
    cr = cl + len;
    if (!rot) {
      rot = true;
    }
  }
}
int solve(int l, int r, bool rot) {
  if (!rot) {
    return get(cl + l, cl + r - 1);
  }
  return get(cr - r, cr - l - 1);
}
int main() {
  ios_base ::sync_with_stdio();
  int c;
  scanf("%d %d", &n, &q);
  cl = 1;
  cr = n + 1;
  int type, x, y;
  for (c = 1; c <= n; c++) {
    a[c] = 1;
    update(c, 1);
  }
  for (c = 1; c <= q; c++) {
    scanf("%d", &type);
    if (type == 1) {
      scanf("%d", &x);
      solve(x, rot);
    } else {
      scanf("%d %d", &x, &y);
      printf("%d\n", solve(x, y, rot));
    }
  }
  return 0;
}
