#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let n = get!(usize);
    let mut lr = get!(usize, usize; n);
    lr.sort_by(|&(l1,r1), &(l2,r2)| {
        if l1.cmp(&l2) == Ordering::Equal {
            r2.cmp(&r1)
        } else {
            l1.cmp(&l2)
        }
    });
    let mx = 1_000_000_000;
    let mut mnr = mx;
    let mut mxl = 0;
    let mut mxlength = 0;
    for &(l,r) in &lr {
        mnr = min!(mnr, r);
        mxl = max!(mxl, l);
        mxlength = max!(mxlength, r-l+1);
    }
    let mut res = mxlength+max!(mnr as isize - mxl as isize+1, 0) as usize;
    let mut forward = vec![(0,0); n+1];
    let mut back = vec![(0,0); n+1];
    forward[0] = (0,mx);
    for i in 0..n {
        forward[i+1] = (max!(forward[i].0, lr[i].0), min!(forward[i].1, lr[i].1));
    }
    back[n] = (0,mx);
    for i in (0..n).rev() {
        back[i] = (max!(back[i+1].0, lr[i].0), min!(back[i+1].1, lr[i].1));
    }

    for i in 1..n {
        let (fl,fr) = forward[i];
        let (bl,br) = back[i];
        let fl = fl as isize;
        let fr = fr as isize;
        let bl = bl as isize;
        let br = br as isize;
        res = max!(res, (max!(fr-fl+1,0)+max!(br-bl+1,0)) as usize);
    }
    println!("{}",res);
}


Measured memory_bytes: 14716