#include <bits/stdc++.h>
using namespace std;
int *a = new int[2000000];
int m, n;
void add(int x, int l);
void sub(int x, int l);
int query(int x, int y, int x0, int y0, int t);
int main() {
  int h, i, j, dir = 1, r, l, o, x, y, len, mid;
  cin >> n >> m;
  for (i = 0; i < 2000000; i++) a[i] = 0;
  for (i = 1; i <= n; i++) add(i, 1);
  l = 1;
  r = n;
  for (i = 0; i < m; i++) {
    cin >> o;
    if (o == 2) {
      cin >> x >> y;
      x++;
      if (dir == 1) {
        x += l - 1;
        y += l - 1;
        cout << query(1, n, x, y, 1) << endl;
      } else if (dir == 2) {
        x = r - x + 1;
        y = r - y + 1;
        cout << query(1, n, y, x, 1) << endl;
      }
    } else {
      cin >> len;
      if (len <= (r - l + 1) / 2) {
        if (dir == 1) {
          mid = l + len;
          for (j = 1; j <= len; j++) {
            x = mid - j;
            y = mid + j - 1;
            h = query(1, n, x, x, 1);
            add(y, h);
          }
          l += len;
        } else if (dir == 2) {
          mid = r - len;
          for (j = 1; j <= len; j++) {
            x = mid + j;
            y = mid - j + 1;
            h = query(1, n, x, x, 1);
            add(y, h);
          }
          r -= len;
        }
      } else {
        len = r - l + 1 - len;
        if (dir == 2) {
          mid = l + len;
          for (j = 1; j <= len; j++) {
            x = mid - j;
            y = mid + j - 1;
            h = query(1, n, x, x, 1);
            add(y, h);
          }
          l += len;
        } else if (dir == 1) {
          mid = r - len;
          for (j = 1; j <= len; j++) {
            x = mid + j;
            y = mid - j + 1;
            h = query(1, n, x, x, 1);
            add(y, h);
          }
          r -= len;
        }
        if (dir == 1)
          dir = 2;
        else
          dir = 1;
      }
    }
  }
  delete[] a;
  return 0;
}
void add(int x0, int l) {
  int x = 1, y = n, mid, t = 1;
  while (1) {
    a[t] += l;
    mid = (x + y) / 2;
    if (x == y) break;
    if (x0 <= mid) {
      y = mid;
      t = t * 2;
    } else {
      x = mid + 1;
      t = t * 2 + 1;
    }
  }
}
void sub(int x0, int l) {
  int x = 1, y = n, mid, t = 1;
  while (1) {
    a[t] -= l;
    mid = (x + y) / 2;
    if (x == y) break;
    if (x0 <= mid) {
      y = mid;
      t = t * 2;
    } else {
      x = mid + 1;
      t = t * 2 + 1;
    }
  }
}
int query(int x, int y, int x0, int y0, int t) {
  int mid;
  if (y0 < x) return 0;
  if (y < x0) return 0;
  if (x0 <= x && y <= y0) {
    return a[t];
  }
  mid = (x + y) / 2;
  return query(x, mid, x0, y0, t * 2) + query(mid + 1, y, x0, y0, t * 2 + 1);
}
