#include <bits/stdc++.h>
int a[100005];
int l, r;
int len, q;
int lowbit(int i) { return i & (-i); }
int sum(int i) {
  int ans = 0;
  while (i) {
    ans += a[i];
    i -= lowbit(i);
  }
  return ans;
}
void change(int pos, int k) {
  while (pos <= len) {
    a[pos] += k;
    pos += lowbit(pos);
  }
}
int fan(int i) { return r - l + 1 - i; }
int main() {
  scanf("%d%d", &len, &q);
  for (int i = 1; i <= len; i++) change(i, 1);
  l = 1, r = len;
  int flag = 0;
  while (q--) {
    int k;
    scanf("%d", &k);
    if (k == 1) {
      int zhe;
      scanf("%d", &zhe);
      if (flag == 0) {
        if (zhe > (r - l + 1) / 2) {
          zhe = fan(zhe);
          flag ^= 1;
          for (int i = r; i > r - zhe; i--) {
            int cc = sum(i) - sum(i - 1);
            int pos = r - 2 * zhe + r - i + 1;
            change(pos, cc);
            change(i, -cc);
          }
          r -= zhe;
        } else {
          for (int i = l; i < l + zhe; i++) {
            int cc = sum(i) - sum(i - 1);
            int pos = l + 2 * zhe - 1 - (i - l);
            change(pos, cc);
            change(i, -cc);
          }
          l += zhe;
        }
      } else {
        if (zhe > (r - l + 1) / 2) {
          zhe = fan(zhe);
          flag ^= 1;
          for (int i = l; i < l + zhe; i++) {
            int cc = sum(i) - sum(i - 1);
            int pos = l + 2 * zhe - 1 - (i - l);
            change(pos, cc);
            change(i, -cc);
          }
          l += zhe;
        } else {
          for (int i = r; i > r - zhe; i--) {
            int cc = sum(i) - sum(i - 1);
            int pos = r - 2 * zhe + r - i + 1;
            change(pos, cc);
            change(i, -cc);
          }
          r -= zhe;
        }
      }
    } else {
      int L, R;
      scanf("%d%d", &L, &R);
      R--;
      if (flag == 1) {
        int k = R;
        R = r - L;
        L = r - k;
      } else {
        L = L + l;
        R = R + l;
      }
      int ans = sum(R) - sum(L - 1);
      printf("%d\n", ans);
    }
  }
}
