#include <functional>
#include <cstdio>
#include <queue>
typedef long long ll; 
std::priority_queue<ll> quel;
std::priority_queue<ll, std::vector<ll>, std::greater<ll> > quer; 
int l[100005], r[100005]; 
int main()
{
	// freopen("ARC070-E.in", "r", stdin); 
	int n; 
	scanf("%d", &n); 
	ll ans = 0, lazy_l = 0, lazy_r = 0; 
	for (int i = 0; i < n; i++)
	{
		scanf("%d%d", l + i, r + i); 
		if (!i)
		{
			quel.push(l[i]); 
			quer.push(l[i]); 
			continue; 
		}
		lazy_l -= r[i] - l[i]; 
		lazy_r += r[i - 1] - l[i - 1]; 
		ll x = quel.top() + lazy_l, y = quer.top() + lazy_r; 
		if (l[i] < x)
		{
			ans += x - l[i]; 
			quer.push(x - lazy_r); 
			quel.push(l[i] - lazy_l); 
			quel.push(l[i] - lazy_l); 
			quel.pop(); 
		}
		else if (l[i] > y)
		{
			ans += l[i] - y; 
			quel.push(y - lazy_l); 
			quer.push(l[i] - lazy_r); 
			quer.push(l[i] - lazy_r); 
			quer.pop(); 
		}
		else
		{
			quel.push(l[i] - lazy_l); 
			quer.push(l[i] - lazy_r); 
		}
	}
	printf("%lld\n", ans);
	return 0; 
}
