#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 0;
bool cmp(const pair<ll,ll> &a, const pair<ll,ll> &b){
  if(a.first==b.first)return a.second > b.second;
  else return a.first < b.first;
}
int main()
{
ll n ;
cin >> n ;
vector<pair<ll,ll>> v(n);
ll rmin=0,lmax=0;
rep(i, n){
  cin >> v[i].first >> v[i].second;
  ans=max(ans,v[i].second-v[i].first+1);
  if(v[rmin].second>v[i].second)rmin=i;
  if(v[lmax].first <v[i].first)lmax=i;
}
ans+=max(0LL,v[rmin].second-v[lmax].first+1);
ll ss=v[rmin].second,t=v[lmax].first;
sort(v.begin(),v.end(),cmp);
multiset<ll> s;
rep(i,n)s.insert(v[i].second);
rep(i,n){
  s.erase(s.find(v[i].second));
  ans=max(ans,max(ss-v[i].first+1,0LL)+max(*s.begin()-t+1,0LL));
}
cout << ans << endl;
return 0;
}
#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;
}