#include <bits/stdc++.h>

#define gc( ) std::getchar( )
#define pc( i ) std::putchar( i )
#define space ' '
#define enter '\n'
#define RE cout << "Passing [" << __FUNCTION__ << "] on " << __LINE__ << enter
#define DEBUG(...) for( auto &i: __VA_ARGS__ ) cout << i << " "; cout << enter
using std::make_pair;

template < typename T >
inline T read( )
{
 T x = 0;
 char ch = gc( );
 bool f = 0;
 while( !std::isdigit( ch ) )
 {
  f = ( ch == '-' );
  ch = gc( );
 }
 while( std::isdigit( ch ) )
 {
  x = x * 10 + ( ch - '0' );
  ch = gc( );
 }
 return f ? -x : x;
}

template < typename T >
void print( T x )
{
 if( x < 0 )
 {
  x = -x;
  pc( '-' );
 }
 if( x < 10 )
 {
  pc( x + 48 );
  return;
 }
 print < T > ( x / 10 );
 pc( x % 10 + 48 );
 return ;
}

namespace Solution
{
#define IOS std::ios::sync_with_stdio( false ), std::cin.tie( 0 ), std::cout.tie( 0 )
#define Rep( i, j, k ) for( int i = j; i >= k; --i )
#define rdi( ) read < int > ( )
#define rdl( ) read < long long > ( )
#define pti( i ) print < int > ( i ), putchar( space )
#define ptl( i ) print < long long > ( i ), putchar( space )
#define For( i, j, k ) for( int i = j; i <= k; ++i )
#define int long long
 using std::cin;
 using std::cout;
 using std::endl;
 using std::vector;
 using std::map;
 using std::queue;
 using std::deque;
 using std::set;
 using std::pair;
 const int N = 204001, mod = 1e9 + 7;
 int n, ans, a[ N * 2 ];
 pair < int, int > p[ N ];
 struct Node
 {
  int l, r, mn;
 }elvahs[ N * 8 ];
#define l( i ) elvahs[ i ].l
#define r( i ) elvahs[ i ].r
#define mn( i ) elvahs[ i ].mn
 inline int ls( int k ) { return k << 1; }
 inline int rs( int k ) { return k << 1 | 1; }
 inline void up( int k ) { mn( k ) = std::min( mn( ls( k ) ), mn( rs( k ) ) ); }
 void Build( int k, int l, int r )
 {
  l( k ) = l;
  r( k ) = r;
  mn( k ) = 2e9;
  if( l == r )
   return;
  int mid = l + r >> 1;
  Build( ls( k ), l, mid );
  Build( rs( k ), mid + 1, r );
  return up( k );
 }
 void Modify( int k, int pos, int x )
 {
  if( l( k ) == r( k ) )
  {
   mn( k ) = std::min( mn( k ), a[ pos ] + x );
   return;
  }
  int mid = l( k ) + r( k ) >> 1;
  pos <= mid ? Modify( ls( k ), pos, x ) : Modify( rs( k ), pos, x ); 
  return up( k );
 }
 int Query( int k, int l, int r )
 {
  if( l <= l( k ) && r( k ) <= r )
   return mn( k );
  int mid = l( k ) + r( k ) >> 1, res = 2e9;
  if( l <= mid )
   res = Query( ls( k ), l, r );
  if( mid < r )
   res = std::min( res, Query( rs( k ), l, r ) );
  return res;
 }
 void Fakemain( )
 {
  IOS;
  cin >> n;
  For( i, 1, n )
   cin >> p[ i ].first >> p[ i ].second;
  std::sort( p + 1, p + 1 + n );
  int cnt = std::unique( p + 1, p + 1 + n ) - p - 1;
  ans = 0;
  For( i, 1, cnt )
   a[ i ] = p[ i ].second;
  For( i, cnt + 1, cnt * 2 )
   a[ i ] = -a[ i - cnt ];
  std::sort( a + 1, a + cnt * 2 + 1 );
  int num = std::unique( a + 1, a + 1 + cnt * 2 ) - a - 1;
  Build( 1, 1, num );
  For( i, 1, cnt )
  {
   int k = std::lower_bound( a + 1, a + 1 + num, p[ i ].second ) - a;
   if( i != 1 )
    ans = std::max( ans, p[ i ].first + p[ i ].second - Query( 1, 1, k ) );
   Modify( 1, k, p[ i ].first );
  }
  For( i, 1, cnt )
   p[ i ].second = -p[ i ].second;
  Build( 1, 1, num );
  For( i, 1, cnt )
  {
   int k = std::lower_bound( a + 1, a + 1 + num, p[ i ].second ) - a;
   if( i != 1 )
    ans = std::max( ans, p[ i ].first + p[ i ].second - Query( 1, 1, k ) );
   Modify( 1, k, p[ i ].first );
  }
  cout << ans;
  return;
 }

} // namespace Solution
#undef int
int main( int argc, char* argv[] )
{
 Solution::Fakemain( );
 return 0;
}

Measured memory_bytes: 34452