#include <bits/stdc++.h>
using namespace std;
#define int long long
pair<int, int> a[300001];
#define f first
#define s second
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, q;
cin >> n >> q;
for (int i = 1;i<n;++i){
int l, r;
cin >> l >> r;
a[i] = {l, r};
}
while(q--){
int t, A, B, C, D;
cin >> t>> A >> B >> C;
if(t==1){
a[A] = {B, C};
}else{
cin >> D;
int res = 0;
if(A < C){
for (int i = A;i<C;++i){
if(B < a[i].f){
B = a[i].f;
}else if(B >= a[i].s){
res += B-a[i].s+1;
B = a[i].s-1;
}
B++;
}
if(B > D)res += B-D;
}else{
for (int i = A-1;i>=C;--i){
if(B < a[i].f){
B = a[i].f;
}else if(B >= a[i].s){
res += B-a[i].s+1;
B = a[i].s-1;
}
B++;
// cout << B << " NGU\n";
}
if(B>D)res += B-D;
}
cout << res << '\n';
}
}
}