#include <bits/stdc++.h>
int l[1000000], r[1000000], s[1000000];
int n, m, a, b, i, j, st, now, ed;
void build(int x, int a, int b) {
  int m;
  l[x] = a;
  r[x] = b;
  s[x] = 1;
  if (b - a > 1) {
    m = (a + b) >> 1;
    build(2 * x, a, m);
    build(2 * x + 1, m, b);
    s[x] = s[2 * x] + s[2 * x + 1];
  }
}
void insert(int x, int a, int b, int c) {
  int m;
  if ((a <= l[x]) && (r[x] <= b)) {
    s[x] = s[x] + c;
    return;
  }
  m = (l[x] + r[x]) >> 1;
  if (a < m) insert(2 * x, a, b, c);
  if (m < b) insert(2 * x + 1, a, b, c);
  s[x] = s[2 * x] + s[2 * x + 1];
}
int query(int x, int a, int b) {
  int m, ans;
  if ((a <= l[x]) && (r[x] <= b)) return s[x];
  m = (l[x] + r[x]) >> 1;
  ans = 0;
  if (a < m) ans = ans + query(2 * x, a, b);
  if (m < b) ans = ans + query(2 * x + 1, a, b);
  return ans;
}
int main() {
  scanf("%d%d", &n, &m);
  build(1, 0, n);
  st = 0;
  ed = n + 1;
  for (i = 1; i <= m; i++) {
    scanf("%d", &a);
    if (a == 1) {
      scanf("%d", &a);
      if (a > (ed - st - 1) - a) {
        now = 1 - now;
        a = (ed - st - 1) - a;
      }
      if (now == 0) {
        for (j = a; j >= 1; j--)
          insert(1, st + a + (a - j), st + a + (a - j) + 1,
                 query(1, st + j - 1, st + j));
        st = st + a;
      } else {
        for (j = a; j >= 1; j--)
          insert(1, ed - a - (a - j + 1) - 1, ed - a - (a - j + 1),
                 query(1, ed - j - 1, ed - j));
        ed = ed - a;
      }
    } else {
      scanf("%d%d", &a, &b);
      if (now == 0)
        printf("%d\n", query(1, st + a, st + b));
      else
        printf("%d\n", query(1, ed - b - 1, ed - a - 1));
    }
  }
}
