#include <bits/stdc++.h>
bool inverse = 0;
int p[500100];
long long dp[500100];
using namespace std;
int main() {
  int n, m, i;
  cin >> n >> m;
  for (i = 0; i < n + 1; i++) p[i] = i;
  int stidx = 0;
  int idx = n;
  for (i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if (a == 1) {
      if (b * 2 > idx - stidx + 1) {
        inverse = !inverse;
        b = idx - stidx - b;
      }
      if (inverse == 0) {
        for (int j = 0; j < 2 * b; j++)
          p[2 * b - j + stidx] =
              p[2 * b - j + stidx] - p[2 * b - j + stidx - 1];
        for (int j = 0; j < b; j++)
          if (j == 0)
            p[stidx + b + j + 1] = p[stidx + b + j + 1] + p[stidx + b - j];
          else
            p[stidx + b + j + 1] =
                p[stidx + b + j + 1] + p[stidx + b - j] + p[stidx + b + j];
        for (int j = 0; j < b; j++) p[stidx + 1 + j] = 0;
        stidx += b;
      } else {
        for (int j = 0; j < b * 2; j++)
          p[idx - j] = p[idx - j] - p[idx - j - 1];
        for (int j = 0; j < b; j++)
          p[idx - 2 * b + j + 1] =
              p[idx - 2 * b + j + 1] + p[idx - 2 * b + j] + p[idx - j];
        for (int j = idx - b + 1; j <= idx; j++) p[j] = 0;
        idx -= b;
      }
    } else {
      int c;
      cin >> c;
      int ans = 0;
      if (inverse == 0) {
        cout << p[stidx + c] - p[stidx + b] << endl;
      } else {
        cout << p[idx - b] - p[idx - c] << endl;
      }
    }
  }
  getchar();
  getchar();
  return 0;
}
