#include<bits/stdc++.h>
#include<tr1/unordered_map>
#define ri register int
using namespace std;
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> poly;
#define pb push_back
const int rlen=1<<18|1,inf=0x3f3f3f3f;
const ll Inf=1e18;
char buf[rlen],*ib=buf,*ob=buf;
#define gc() (((ib==ob)&&(ob=(ib=buf)+fread(buf,1,rlen,stdin)),ib==ob)?-1:*ib++)
inline int read() {
  int ans=0;
  bool f=1;
  char ch=gc();
  while(!isdigit(ch)) f^=ch=='-',ch=gc();
  while(isdigit(ch)) ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
  return f?ans:-ans;
}
inline ll readl() {
  ll ans=0;
  bool f=1;
  char ch=gc();
  while(!isdigit(ch)) f^=ch=='-',ch=gc();
  while(isdigit(ch)) ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
  return f?ans:-ans;
}
inline int Read(char*s) {
  int tp=0;
  char ch=gc();
  while(!isdigit(ch)&&!isalpha(ch)) ch=gc();
  while(isdigit(ch)||isalpha(ch)) s[++tp]=ch,ch=gc();
  return tp;
}
namespace modular {
  const int mod=1e9+7;
  inline int add(int a,int b) { return a+b<mod?a+b:a+b-mod; }
  inline int dec(int a,int b) { return a<b?a-b+mod:a-b; }
  inline int mul(int a,int b) { return (ll)a*b%mod; }
  inline void Add(int&a,int b) { a=a+b<mod?a+b:a+b-mod; }
  inline void Dec(int&a,int b) { a=a<b?a-b+mod:a-b; }
  inline void Mul(int&a,int b) { a=(ll)a*b%mod; }
  inline int ksm(int a,int p) { int ret=1;for(;p;p>>=1,Mul(a,a)) (p&1)&&(Mul(ret,a),1);return ret; }
  inline int Inv(int a) { return ksm(a,mod-2); }
  inline int sqr(int a) { return mul(a,a); }
  inline int cub(int a) { return (ll)a*a%mod*a%mod; }
}
using namespace modular;
template<typename T> inline void ckmax(T&a,T b) { a<b?a=b:0; }
template<typename T> inline void ckmin(T&a,T b) { a>b?a=b:0; }
template<typename T> inline T gcd(T a,T b) { T t;while(b)t=a,a=b,b=t-t/a*a;return a; }
template<typename T> inline T Abs(T x) { return x<0?-x:x; }
inline int rd() { return rand()|(rand()<<15); }
const int N=5e5+5;
int n,pre[N],suf[N];
pii a[N];
int main() {
  #ifdef ldxcaicai
  freopen("lx.in","r",stdin);
  #endif
  n=read();
  for(ri i=1;i<=n;++i) a[i].fi=read(),a[i].se=read();
  sort(a+1,a+n+1);
  pre[0]=0x3f3f3f3f,suf[n]=0x3f3f3f3f;
  for(ri i=1;i<n;++i) pre[i]=min(pre[i-1],a[i].se);
  for(ri i=n-1;i;--i) suf[i]=min(suf[i+1],a[i].se);
  int res=0;
  for(ri mn,r1,r2,t,i=1;i<n;++i) {
    r1=a[i].se,r2=min(max(suf[i+1],a[n].fi-1),a[n].se);
    t=(r1-a[i].fi+1)+(r2-a[n].fi+1);
    mn=pre[i-1];
    ckmax(res,t-max(0,min(r1-max(a[i].fi-1,mn),r2-max(a[n].fi-1,mn))));
  }
  cout<<res;
  return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
#define all(x) x.begin(),x.end()
const int maxn = 100010;
const int INF = INT_MAX/2;

int n;
vector <pi> v;
int pre[maxn],suf[maxn];

int dist(int x, int y) {
	return max(y - x + 1,0ll);
}

int32_t main() {
	FAST
	cin >> n;
	v.push_back(pi(0,0));
	for (int i =1;i<=n;i++) {
		int a,b; cin >> a >> b;
		v.push_back(pi(a,b));
	}
	sort(all(v));
	
	//CASE 1: All .f of group 1 < All .f of group 2
	//prefix[i] from 1 to i
	int maxl=0, minr=INF;
	
	for (int i = 1;i<=n;i++) {
		maxl = max(maxl,v[i].f); 
		minr = min(minr,v[i].s);
		
		pre[i] = dist(maxl,minr);
	}
	int whack = pre[n];
	
	//Suffix[i] from n to i+1
	maxl = 0; minr = INF;
	for (int i =n-1;i>=1;i--) {
		maxl = max(maxl,v[i+1].f);
		minr = min(minr,v[i+1].s);
		
		suf[i] = dist(maxl,minr);
	}
	int ans = 0;
	for (int i =1;i<n;i++) {
		ans = max(ans, pre[i] + suf[i]);
	}
	
	//CASE 2: Just take largest guy for group 1 and throw the rest into group 2.
	
	for (int i =1;i<=n;i++) {
		ans = max(ans, whack + dist(v[i].f,v[i].s));
	}
	cout << ans;
}






