#include <bits/stdc++.h>
using namespace std;
int tree[100000 * 4], prop[100000 * 4];
int get(int l, int r, int n = 1, int rl = 0, int rr = 100000) {
  if (prop[n]) {
    tree[n] += (rr - rl + 1) * prop[n];
    if (n < 200000) {
      prop[n * 2] += prop[n];
      prop[n * 2 + 1] += prop[n];
    }
    prop[n] = 0;
  }
  if (rl > r || rr < l) return 0;
  if (rl == rr) return tree[n];
  if (rl >= l && rr <= r) return tree[n];
  return get(l, r, n * 2, rl, (rl + rr) / 2) +
         get(l, r, n * 2 + 1, (rl + rr) / 2 + 1, rr);
}
void insert(int l, int r, int val, int n = 1, int rl = 0, int rr = 100000) {
  if (rl > r || rr < l) return;
  if (rl == rr)
    tree[n] += val;
  else if (rl >= l && rr <= r)
    prop[n] += val;
  else {
    insert(l, r, val, n * 2, rl, (rl + rr) / 2);
    insert(l, r, val, n * 2 + 1, (rl + rr) / 2 + 1, rr);
    tree[n] += (min(rr, r) - max(l, rl) + 1) * val;
  }
}
int width, queries;
int direc = 1;
int start = 0;
int main() {
  cin >> width >> queries;
  insert(0, width - 1, 1);
  for (int i = 0; i < queries; i++) {
    int q;
    cin >> q;
    if (q == 1) {
      int pos;
      cin >> pos;
      if (pos > width / 2) {
        pos = width - pos;
        start += width * direc;
        direc *= -1;
      }
      if (direc == -1) {
        for (int i = 0; i < pos; i++) {
          insert(start - pos * 2 + i, start - pos * 2 + i,
                 get(start - i - 1, start - i - 1));
        }
      } else {
        for (int i = 0; i < pos; i++) {
          insert(start + pos * 2 - i - 1, start + pos * 2 - i - 1,
                 get(start + i, start + i));
        }
      }
      start += pos * direc;
      width -= min(pos, width - pos);
    } else {
      int a, b;
      cin >> a >> b;
      if (direc == 1) {
        cout << get(start + a, start + b - 1) << "\n";
      } else {
        cout << get(start - b, start - a - 1) << "\n";
      }
    }
  }
}
