#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5;
int _w;

struct Seg {
  int l , r;
  Seg() {} Seg( int l , int r ):l( l ) , r( r ) {}
  bool operator < ( const Seg & rhs ) const { return l < rhs.l; }
  Seg operator ^ ( const Seg & rhs ) const { return Seg( max( l , rhs.l ) , min( r , rhs.r ) ); }
  int length( void ) { return max( 0 , r - l + 1 ); }
} dat[N] , pre[N] , suf[N];

int n , ans;

int main( void ) {
  _w = scanf("%d",&n);
  for( int i = 1 ; i <= n ; ++i )
    _w = scanf("%d%d",&dat[i].l,&dat[i].r);
  sort( dat + 1 , dat + 1 + n );
  pre[0] = suf[n + 1] = Seg( 0 , 1e9 );
  for( int i = 1 ; i <= n ; ++i ) pre[i] = pre[i - 1] ^ dat[i];
  for( int i = n ; i ; --i ) suf[i] = suf[i + 1] ^ dat[i];
  for( int i = 1 ; i <= n ; ++i )
    ans = max( ans , ( pre[i - 1] ^ suf[i + 1] ).length() + dat[i].length() );
  for( int i = 1 ; i < n ; ++i )
    ans = max( ans , pre[i].length() + suf[i + 1].length() );
  cout << ans;
  return 0;
}
