#include <bits/stdc++.h>
using namespace std;
const int BUF = 100005;
const int QUERY = 100005;
class Bit {
 public:
  int n, tree[BUF];
  Bit(int n) {
    this->n = n;
    memset(tree, 0, sizeof(tree));
  }
  int get(int idx) {
    ++idx;
    int ret = 0;
    for (int i = idx; i; i -= i & -i) {
      ret += tree[i];
    }
    return ret;
  }
  int get(int L, int R) { return get(R) - get(L - 1); }
  void add(int idx, int delta) {
    ++idx;
    for (int i = idx; i <= n; i += i & -i) {
      tree[i] += delta;
    }
  }
};
int n, nQuery;
int query[QUERY][3];
void read() {
  scanf("%d%d", &n, &nQuery);
  for (int i = 0; i < nQuery; ++i) {
    scanf("%d", &query[i][0]);
    for (int j = 0; j < query[i][0]; ++j) scanf("%d", &query[i][j + 1]);
  }
}
void work() {
  Bit bit = Bit(n);
  for (int i = 0; i < n; ++i) {
    bit.add(i, 1);
  }
  int bgn = 0, end = n - 1;
  for (int loop = 0; loop < nQuery; ++loop) {
    if (query[loop][0] == 1) {
      int pos = query[loop][1];
      if (bgn < end) {
        pos += bgn;
        if (pos - bgn < end - pos + 1) {
          for (int i = pos - 1, j = pos; i >= bgn; --i, ++j) {
            bit.add(j, bit.get(i, i));
          }
          bgn = pos;
        } else {
          for (int i = pos, j = pos - 1; i <= end; ++i, --j) {
            bit.add(j, bit.get(i, i));
          }
          end = bgn;
          bgn = pos - 1;
        }
      } else {
        pos = bgn - pos;
        if (bgn - pos < pos - end + 1) {
          for (int i = pos + 1, j = pos; i <= bgn; ++i, --j) {
            bit.add(j, bit.get(i, i));
          }
          bgn = pos;
        } else {
          for (int i = pos, j = pos + 1; i >= end; --i, ++j) {
            bit.add(j, bit.get(i, i));
          }
          end = bgn;
          bgn = pos + 1;
        }
      }
    } else {
      int L = query[loop][1], R = query[loop][2];
      if (bgn < end) {
        L += bgn;
        R += bgn;
        printf("%d\n", bit.get(L, R - 1));
      } else {
        L = bgn - L;
        R = bgn - R;
        printf("%d\n", bit.get(R + 1, L));
      }
    }
  }
}
int main() {
  read();
  work();
  return 0;
}
