#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n, m;
struct {
  int r, l;
  int val;
} tree[maxn << 2];
void build(int tis, int l, int r) {
  tree[tis].r = r, tree[tis].l = l;
  tree[tis].val = r - l + 1;
  if (r == l)
    return;
  else {
    int mid = (l + r) >> 1;
    build(tis << 1, l, mid);
    build(tis << 1 | 1, mid + 1, r);
  }
}
int find(int tis, int l, int r, int tp) {
  if (l == r && r == tp)
    return tree[tis].val;
  else {
    int mid = (l + r) >> 1;
    if (mid >= tp)
      return find(tis << 1, l, mid, tp);
    else
      return find(tis << 1 | 1, mid + 1, r, tp);
  }
}
void change(int tis, int l, int r, int tp, int val) {
  if (l == r && r == tp)
    tree[tis].val += val;
  else {
    int mid = (l + r) >> 1;
    if (mid >= tp)
      change(tis << 1, l, mid, tp, val);
    else
      change(tis << 1 | 1, mid + 1, r, tp, val);
    tree[tis].val = tree[tis << 1].val + tree[tis << 1 | 1].val;
  }
}
int query(int tis, int l, int r, int fl, int fr) {
  if (l >= fl && r <= fr)
    return tree[tis].val;
  else {
    int ans = 0;
    int mid = (l + r) >> 1;
    if (mid >= fl) ans += query(tis << 1, l, mid, fl, fr);
    if (mid + 1 <= fr) ans += query(tis << 1 | 1, mid + 1, r, fl, fr);
    return ans;
  }
}
int main() {
  scanf("%d %d", &n, &m);
  build(1, 1, n);
  int len = n;
  int L = 1, R = n;
  int tag = 0;
  int revers = 0;
  while (m--) {
    scanf("%d", &tag);
    if (tag == 1) {
      int p;
      scanf("%d", &p);
      if (revers == 0) {
        if (len / 2 >= p) {
          int i = L + p - 1;
          int j = L + p;
          for (int k = 0; k < p; k++) {
            int temp = find(1, 1, n, i - k);
            change(1, 1, n, j + k, temp);
          }
          L += p;
          len -= p;
        } else {
          int i = L + p - 1;
          int j = L + p;
          for (int k = 0; k < len - p; k++) {
            int temp = find(1, 1, n, j + k);
            change(1, 1, n, i - k, temp);
          }
          revers ^= 1;
          R -= len - p;
          len -= (len - p);
        }
      } else {
        if (len / 2 >= p) {
          int i = R - p + 1;
          int j = R - p;
          for (int k = 0; k < p; k++) {
            int temp = find(1, 1, n, i + k);
            change(1, 1, n, j - k, temp);
          }
          R -= p;
          len -= p;
        } else {
          int i = R - p + 1;
          int j = R - p;
          for (int k = 0; k < len - p; k++) {
            int temp = find(1, 1, n, j - k);
            change(1, 1, n, i + k, temp);
          }
          L += (len - p);
          revers ^= 1;
          len -= (len - p);
        }
      }
    } else {
      int l, r;
      scanf("%d %d", &l, &r);
      if (revers == 0) {
        int ans = query(1, 1, n, L + l, L + r - 1);
        printf("%d\n", ans);
      } else {
        int ans = query(1, 1, n, R - r + 1, R - l);
        printf("%d\n", ans);
      }
    }
  }
}
