#include <bits/stdc++.h>
using namespace std;
int PASSED_POINT = 0;
void Duxar() {}
void read_int(int &value) {
  int sign = 1;
  char ch;
  value = 0;
  while (!isdigit(ch = getchar())) {
    (ch == '-') && (sign = -1);
  }
  do {
    value = value * 10 + (ch - '0');
  } while (isdigit(ch = getchar()));
  value *= sign;
}
int N, Q, start = 1, last;
vector<int> paper, values;
void update_bit(vector<int> &BIT, int pos, int value);
int compute_bit(vector<int> &BIT, int pos);
void show(vector<int> V) {
  for (auto x : V) {
    printf("%d ", x);
  }
  printf("\n");
}
int main() {
  int i, a, b, c, pos, apos;
  bool isok = true;
  read_int(N);
  read_int(Q);
  last = N;
  paper.resize(N + 1);
  values.resize(N + 1, 1);
  for (i = 1; i <= N; ++i) {
    update_bit(paper, i, 1);
  }
  for (i = 0; i < Q; ++i) {
    read_int(c);
    if (c == 1) {
      read_int(pos);
      if (isok)
        apos = start + pos - 1;
      else
        apos = last - pos;
      if (apos - start + 1 <= last - apos) {
        for (a = apos, b = apos + 1; a >= start; --a, ++b) {
          update_bit(paper, b, values[a]);
          values[b] += values[a];
          update_bit(paper, a, -values[a]);
          values[a] = 0;
        }
        start = apos + 1;
        if (!isok) isok = true;
      } else {
        for (a = apos + 1, b = apos; a <= last; ++a, --b) {
          update_bit(paper, b, values[a]);
          values[b] += values[a];
          update_bit(paper, a, -values[a]);
          values[a] = 0;
        }
        last = apos;
        if (isok) isok = false;
      }
    } else {
      read_int(a);
      read_int(b);
      if (isok) {
        printf("%d\n", compute_bit(paper, start + b - 1) -
                           compute_bit(paper, start + a - 1));
      } else {
        printf("%d\n",
               compute_bit(paper, last - a) - compute_bit(paper, last - b));
      }
    }
  }
  return 0;
}
void update_bit(vector<int> &BIT, int pos, int value) {
  int i;
  for (i = pos; i <= N; i += ((i ^ (i - 1)) & i)) {
    BIT[i] += value;
  }
}
int compute_bit(vector<int> &BIT, int pos) {
  int i, ans = 0;
  for (i = pos; i > 0; i -= ((i ^ (i - 1)) & i)) {
    ans += BIT[i];
  }
  return ans;
}
