#include <bits/stdc++.h>
using namespace std;
int a[100000 + 342];
int dp[100000 + 342];
int main() {
  int n, m, choice, x;
  int parity = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    a[i] = 1;
    dp[i] = dp[i - 1] + a[i];
  }
  int lbound = 0, rbound = n;
  while (m--) {
    cin >> choice;
    if (choice == 1) {
      cin >> x;
      if (m == 1) {
      }
      int mid = (lbound + rbound) / 2;
      if (parity == 0) {
        if (lbound + x <= mid) {
          for (int i = lbound + x + 1, j = lbound + x; j > lbound; i++, j--) {
            a[i] += a[j];
            if (i == lbound + x + 1) {
              dp[i] = a[i];
            } else {
              dp[i] = dp[i - 1] + a[i];
            }
          }
          lbound = lbound + x;
          dp[lbound] = 0;
        } else {
          int final_i_value = lbound + x;
          for (int i = lbound + x, j = lbound + x + 1; j <= rbound; i--, j++) {
            a[i] += a[j];
            final_i_value = i;
          }
          for (int i = final_i_value; i <= lbound + x; i++) {
            dp[i] = dp[i - 1] + a[i];
          }
          rbound = lbound + x;
          parity = 1;
        }
      } else {
        mid = (lbound + rbound + 1) / 2;
        int xx = rbound - x;
        if (xx >= mid) {
          int final_i_value = xx;
          for (int i = xx, j = xx + 1; j <= rbound; i--, j++) {
            a[i] += a[j];
            final_i_value = i;
          }
          for (int i = final_i_value; i <= xx; i++) {
            dp[i] = dp[i - 1] + a[i];
          }
          rbound = xx;
        } else {
          dp[xx] = 0;
          for (int i = xx + 1, j = xx; j > lbound; j--, i++) {
            a[i] += a[j];
            if (i == xx) {
              dp[i] = a[i];
            } else {
              dp[i] = dp[i - 1] + a[i];
            }
          }
          lbound = xx;
          dp[lbound] = 0;
          parity = 0;
        }
      }
    } else {
      int lll, rrr;
      cin >> lll >> rrr;
      if (parity == 0) {
        cout << dp[lbound + rrr] - dp[lbound + lll] << "\n";
      } else {
        cout << dp[rbound - lll] - dp[rbound - rrr] << "\n";
      }
    }
    if (m == 2) {
    }
    if (m == 1) {
    }
  }
  return 0;
}
