#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

struct LR
{
	long long l;
	long long r;

};

struct LR a[1000000];
int n;

bool compareLR(struct LR a, struct LR b)
{
	if (a.l < b.l)
		return true;
	else if (a.l > b.l)
		return false;
	else
	{
		if (a.r <= b.r)
			return true;
		else
			return false;
	}
}

bool compareLR_R(struct LR a, struct LR b)
{
	if (a.l < b.l)
		return false;
	else if (a.l > b.l)
		return true;
	else
	{
		if (a.r <= b.r)
			return false;
		else
			return true;
	}
}



long long Caculate(struct LR a, struct LR b)
{
	long long maxL = 0;
	long long minR = 1999999999;

	maxL = a.l >= b.l ? a.l : b.l;
	minR = a.r <= b.r ? a.r : b.r;

	long long result = minR - maxL + 1;
	result = result < 0 ? 0 : result;

	return result;

}

bool compareLR_S(struct LR a, struct LR b)
{
	long long tmpA = Caculate(a, a);
	long long tmpB = Caculate(b, b);

	if (tmpA < tmpB)
		return true;
	else
		return false;
}

int main()
{
	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> a[i].l >> a[i].r;		
	}
		
	long long calA = 0;
	long long calB = 0;
	long long tmpA = 0;
	long long tmpB = 0;
	long long sumA, sumB, sumC;
	struct LR Aindex;
	struct LR Bindex;

	sort(a, a + n, compareLR);

	calA = Caculate(a[0], a[0]);
	calB = Caculate(a[n - 1], a[n - 1]);
	
	Aindex.l = a[0].l;
	Aindex.r = a[0].r;
	
	Bindex.l = a[n-1].l;
	Bindex.r = a[n-1].r;

	for (int i = 1; i < n - 1; i++)
	{
		tmpA = Caculate(Aindex, a[i]);
		tmpB = Caculate(Bindex, a[i]);

		if (calA + tmpB > calB + tmpA)
		{
			calB = tmpB;
			Bindex.l = a[i].l >= Bindex.l ? a[i].l : Bindex.l;
			Bindex.r = a[i].r <= Bindex.r ? a[i].r : Bindex.r;
		}
		else
		{
			calA = tmpA;
			Aindex.l = a[i].l >= Aindex.l ? a[i].l : Aindex.l;
			Aindex.r = a[i].r <= Aindex.r ? a[i].r : Aindex.r;
		}

	}
	sumA = calA + calB;
	
	sort(a, a + n, compareLR_R);

	calA = Caculate(a[0], a[0]);
	calB = Caculate(a[n - 1], a[n - 1]);

	Aindex.l = a[0].l;
	Aindex.r = a[0].r;

	Bindex.l = a[n - 1].l;
	Bindex.r = a[n - 1].r;

	for (int i = 1; i < n - 1; i++)
	{
		tmpA = Caculate(Aindex, a[i]);
		tmpB = Caculate(Bindex, a[i]);

		if (calA + tmpB > calB + tmpA)
		{
			calB = tmpB;
			Bindex.l = a[i].l >= Bindex.l ? a[i].l : Bindex.l;
			Bindex.r = a[i].r <= Bindex.r ? a[i].r : Bindex.r;
		}
		else
		{
			calA = tmpA;
			Aindex.l = a[i].l >= Aindex.l ? a[i].l : Aindex.l;
			Aindex.r = a[i].r <= Aindex.r ? a[i].r : Aindex.r;
		}

	}
	sumB = calA + calB;

	sort(a, a + n, compareLR_S);

	calA = Caculate(a[0], a[0]);
	calB = Caculate(a[n - 1], a[n - 1]);

	Aindex.l = a[0].l;
	Aindex.r = a[0].r;

	Bindex.l = a[n - 1].l;
	Bindex.r = a[n - 1].r;

	for (int i = 1; i < n - 1; i++)
	{
		tmpA = Caculate(Aindex, a[i]);
		tmpB = Caculate(Bindex, a[i]);

		if (calA + tmpB > calB + tmpA)
		{
			calB = tmpB;
			Bindex.l = a[i].l >= Bindex.l ? a[i].l : Bindex.l;
			Bindex.r = a[i].r <= Bindex.r ? a[i].r : Bindex.r;
		}
		else
		{
			calA = tmpA;
			Aindex.l = a[i].l >= Aindex.l ? a[i].l : Aindex.l;
			Aindex.r = a[i].r <= Aindex.r ? a[i].r : Aindex.r;
		}

	}
	sumC = calA + calB;


	if (sumA > sumB)
		if (sumA > sumC)
			cout << sumA << endl;
		else
			cout << sumC << endl;
	else
		if (sumB > sumC)
			cout << sumB << endl;
		else
			cout << sumC << endl;

	//cout << calA << ' ' << calB << endl;
	//cout << Aindex.l << ' ' << Aindex.r << endl;
	//cout << Bindex.l << ' ' << Bindex.r << endl;
	/*
	cout << endl;
	for (int i = 0; i < n; i++)
	{
		cout << a[i].l << ' ' << a[i].r << ' ' << Caculate(a[i], a[i]) << endl;
		
	}
	*/

	return 0;
}

Measured memory_bytes: 1792