#include <bits/stdc++.h>
using namespace std;
const int MaxN = 100009;
int N;
vector<int> d(4 * MaxN, 0);
vector<int> help(MaxN, 0);
void build(int i, int l, int r) {
  if (l + 1 == r) {
    d[i] = 1;
  } else {
    int m = (l + r) / 2;
    build(2 * i + 1, l, m);
    build(2 * i + 2, m, r);
    d[i] = d[2 * i + 1] + d[2 * i + 2];
  }
}
int get(int i, int l, int r, int a, int b) {
  if (l >= b || r <= a) return 0;
  if (l >= a && r <= b) return d[i];
  int m = (l + r) / 2;
  return get(2 * i + 1, l, m, a, b) + get(2 * i + 2, m, r, a, b);
}
void update(int i, int l, int r, int a, int b, bool e) {
  if (l >= b || r <= a) return;
  if (l + 1 == r) {
    if (e) {
      int u = get(0, 0, N, 2 * a - l - 1, 2 * a - l);
      d[i] += u;
    } else {
      int u = get(0, 0, N, 2 * b - l - 1, 2 * b - l);
      d[i] += u;
    }
  } else {
    int m = (l + r) / 2;
    update(2 * i + 1, l, m, a, b, e);
    update(2 * i + 2, m, r, a, b, e);
    d[i] = d[2 * i + 1] + d[2 * i + 2];
  }
}
void updateAfter(int i, int l, int r, int a, int b) {
  if (l >= b || r <= a) return;
  if (l + 1 == r)
    d[i] = 0;
  else {
    int m = (l + r) / 2;
    updateAfter(2 * i + 1, l, m, a, b);
    updateAfter(2 * i + 2, m, r, a, b);
    d[i] = d[2 * i + 1] + d[2 * i + 2];
  }
}
void print(int i, int l, int r) {
  if (l + 1 == r)
    cout << d[i] << " ";
  else {
    int m = (l + r) / 2;
    print(2 * i + 1, l, m);
    print(2 * i + 2, m, r);
  }
}
void reverce(int i, int l, int r) {
  if (l + 1 == r) return;
  int m = (l + r) / 2;
  int buf = d[2 * i + 1];
  d[2 * i + 1] = d[2 * i + 2];
  d[2 * i + 2] = d[2 * i + 1];
}
int main() {
  int n, q;
  cin >> n >> q;
  N = n;
  int now = 0;
  int ending = n;
  build(0, 0, n);
  bool b = true;
  for (int i = 0; i < q; i++) {
    int t;
    cin >> t;
    if (t == 1) {
      int l;
      cin >> l;
      if (2 * l <= ending - now) {
        if (b) {
          update(0, 0, n, now + l, now + 2 * l, 1);
          now += l;
        } else {
          update(0, 0, n, ending - 2 * l, ending - l, 0);
          ending -= l;
        }
      } else {
        if (b) {
          update(0, 0, n, 2 * now + 2 * l - ending, now + l, 0);
          ending = now + l;
        } else {
          update(0, 0, n, ending - l, 2 * ending - 2 * l - now, 1);
          now = ending - l;
        }
        b = 1 - b;
      }
    } else {
      int l, r;
      cin >> l >> r;
      if (b) {
        cout << get(0, 0, n, now + l, now + r) << endl;
      } else {
        cout << get(0, 0, n, ending - r, ending - l) << endl;
      }
    }
  }
  return 0;
}
