#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include<string>
#include<iostream>
#include<list>
using namespace std;
int main() {
int n = 0, m = 0;
while (scanf("%d%d",&n,&m) == 2) {
list<long long int>one;
for (long long int i = 1; i <= n; i++) {
one.push_back(i);
}
for (long long int j = 1; j <= m; j++) {
long long int t = 0, k = 0, q = 0;
long long int x = 0, y = 0;
list<long long int>::iterator fr, sc;
scanf("%d", &t);
switch (t){
case 1:
case 2:
case 3:
scanf("%d%d", &k, &q); if (k == q)continue;
for (fr = one.begin(); *fr != k; fr++, x++);
for (sc = one.begin(); *sc != q; sc++, y++);
switch (t) {
case 1:
if (x==y-1) continue;
else { one.insert(sc, *fr); one.erase(fr); }
break;
case 2:
if (x==y+1) continue;/*insert的本质*/
else { one.insert(++sc, *fr); one.erase(fr); }
break;
case 3:
swap(*fr, *sc);
break;
}
break;
case 4:
one.reverse();
break;
default:
continue;
}
}
long long int sum = 0, k = 1;
list<long long int>::iterator it;
for (it=one.begin(); it!=one.end(); it++, k++)if (k % 2 != 0)sum += *it;
::cout << sum;
::cout << "\n";
}
return 0;
}
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<list>
using namespace std;
int main() {
int n = 0, m = 0;
while (scanf("%d%d",&n,&m) == 2) {
long long int num[100005] = { 0 };
for (long long int i = 1; i <= n; i++) {
num[i - 1] = i;
}
list<long long int>one(num,num+n);
for (long long int j = 1; j <= m; j++) {
int t = 0, k = 0, q = 0;
int x = 0, y = 0;
list<long long int>::iterator fr, sc;
scanf("%d", &t);
switch (t){
case 1:
case 2:
case 3:
scanf("%d%d", &k, &q); if (k == q)continue;
for (fr = one.begin(); *fr != k; fr++, x++);
for (sc = one.begin(); *sc != q; sc++, y++);
switch (t) {
case 1:
if (x==y-1) continue;
else { one.insert(sc, *fr); one.erase(fr); }
break;
case 2:
if (x==y+1) continue;/*insert的本质*/
else { one.insert(++sc, *fr); one.erase(fr); }
break;
case 3:
swap(*fr, *sc);
break;
}
break;
case 4:
one.reverse();
break;
default:
continue;
}
}
long long int sum = 0, k = 1;
list<long long int>::iterator it;
for (it=one.begin(); it!=one.end(); it++, k++)if (k % 2 != 0)sum += *it;
::cout << sum;
::cout << "\n";
}
return 0;
}