"use strict";
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}
var n,q;

console.log(main());
function main(){
  n = o.a();
  q = o.m(n);
  q.sort((a,b)=>a[1]>b[1]?1:a[1]<b[1]?-1:a[0]-b[0]);
  var ans = solve();
  q.sort((a,b)=>a[0]>b[0]?1:a[0]<b[0]?-1:a[1]-b[1]);
  ans = Math.max(ans,solve());
  var x = xArray("[0,1e9]",n);
  var y = xArray("[0,1e9]",n);
  var l = q[0][0], r = q[0][1];
  for(var i = 1; i < n; i++){
    if(l < q[i-1][0])l = q[i-1][0];
    if(r > q[i-1][1])r = q[i-1][1];
    x[i][0] = l, x[i][1] = r;
  }
  var l = q[n-1][0], r = q[n-1][1];
  for(var i = n-2; i >= 0; i--){
    if(l < q[i+1][0])l = q[i+1][0];
    if(r > q[i+1][1])r = q[i+1][1];
    y[i][0] = l, y[i][1] = r;
  }
  for(var i = 0; i < n; i++){
    var t = q[i][1]-q[i][0]+1;
    var l = Math.max(x[i][0], y[i][0]);
    var r = Math.min(x[i][1], y[i][1]);
    if(l <= r)t += r-l+1;
    if(ans < t)ans = t;
  }
  return ans;
}

function solve(){
  var l = 0, r = 1e9, x = xArray(0,n);
  for(var i = n-1; i; i--){
    if(l < q[i][0])l = q[i][0];
    if(r > q[i][1])r = q[i][1];
    if(l > r)break;
    x[i] = r-l+1;
  }
  l = 0, r = 1e9;
  var res = 0;
  for(var i = 0; i < n-1; i++){
    if(l < q[i][0])l = q[i][0];
    if(r > q[i][1])r = q[i][1];
    if(l > r)break;
    var t = r-l+1 + x[i+1];
    if(res < t)res = t;
  }
  return res
}