#include <bits/stdc++.h>
using namespace std;
int a[100050];
int c[100050];
int n, q;
int lowbit(int t) { return t & -t; }
void add(int p, int va) {
  while (p <= n) {
    c[p] += va;
    p += lowbit(p);
  }
}
int getsum(int p) {
  int res = 0;
  while (p > 0) {
    res += c[p];
    p -= lowbit(p);
  }
  return res;
}
int main() {
  memset(a, 0, sizeof(a));
  memset(c, 0, sizeof(c));
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; ++i) {
    a[i] = 1;
    add(i, 1);
  }
  int flag = 0;
  int nowl = 0, nowr = n;
  while (q--) {
    int x, l, r, y;
    scanf("%d", &x);
    if (x == 1) {
      scanf("%d", &y);
      int len = nowr - nowl;
      if (y <= len - y) {
        if (flag == 0) {
          for (int i = nowl + 1; i <= nowl + y; ++i) {
            int now = 2 * (nowl + y) - i + 1;
            a[now] += a[i];
            add(i, -a[i]);
            add(now, a[i]);
          }
          nowl = nowl + y;
        } else {
          for (int i = nowr; i > nowr - y; --i) {
            int now = 2 * (nowr - y) - i + 1;
            a[now] += a[i];
            add(i, -a[i]);
            add(now, a[i]);
          }
          nowr = nowr - y;
        }
      } else {
        y = len - y;
        if (flag == 0) {
          for (int i = nowr; i > nowr - y; --i) {
            int now = 2 * (nowr - y) - i + 1;
            a[now] += a[i];
            add(i, -a[i]);
            add(now, a[i]);
          }
          nowr = nowr - y;
        } else {
          for (int i = nowl + 1; i <= nowl + y; ++i) {
            int now = 2 * (nowl + y) - i + 1;
            a[now] += a[i];
            add(i, -a[i]);
            add(now, a[i]);
          }
          nowl = nowl + y;
        }
        flag = 1 - flag;
      }
    } else {
      scanf("%d%d", &l, &r);
      if (flag == 0) {
        int sum1 = getsum(nowl + r);
        int sum2 = getsum(nowl + l);
        printf("%d\n", sum1 - sum2);
      } else {
        int sum1 = getsum(nowr - l);
        int sum2 = getsum(nowr - r);
        printf("%d\n", sum1 - sum2);
      }
    }
  }
}
