package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
		if len(os.Args) > 2 {
			wfp, _ = os.Create(os.Args[2])
		}
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	ee := make(Enables, n)

	mlen := 0
	for i := 0; i < n; i++ {
		ee[i].l = getNextInt(scanner)
		ee[i].r = getNextInt(scanner) + 1
		if mlen < ee[i].r-ee[i].l {
			mlen = ee[i].r - ee[i].l
		}
	}
	sort.Sort(ee)
	seg := Segment{}
	seg.init(n)
	for i := 0; i < n; i++ {
		seg.minimize(i, ee[i].r)
	}
	t := seg.top()
	var ans int64
	ans = int64(mlen) + int64(maxint(ee[t].r-ee[n-1].l, 0))

	mr := ee[n-1].r
	for i := n - 1; i >= 0; i-- {
		l := ee[t].r - ee[t].l
		if i > 0 {
			l = maxint(ee[t].r-ee[i-1].l, 0)
		}
		if mr > ee[i].r {
			mr = ee[i].r
		}
		r := maxint(mr-ee[n-1].l, 0)
		if ans < int64(l)+int64(r) {
			ans = int64(l) + int64(r)
		}
	}

	fmt.Fprintln(writer, ans)
	writer.Flush()
}

func maxint(a int, b int) int {
	if a > b {
		return a
	}
	return b
}

type Enable struct {
	l, r int
}

type Enables []Enable

func (a Enables) Len() int      { return len(a) }
func (a Enables) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a Enables) Less(i, j int) bool {
	if a[i].l == a[j].l {
		return a[i].r < a[j].r
	}
	return a[i].l < a[j].l
}

// Segment ...
type Segment struct {
	n, h, i, chunk, inf int
	unit                []int
	bucket              [][]int
}

func (seg *Segment) init(n int) {
	seg.n = n
	seg.unit = make([]int, 1)
	seg.unit[0] = 1
	seg.bucket = make([][]int, 1)
	seg.bucket[0] = make([]int, n)

	chunk := 8
	for i := 0; n > 1; i++ {
		n = (n-1)/chunk + 1
		seg.bucket = append(seg.bucket, make([]int, n))
		seg.unit = append(seg.unit, seg.unit[i]*chunk)
	}
	seg.h = len(seg.unit)
	seg.chunk = chunk
	seg.inf = math.MaxInt32
}

func (seg *Segment) minimize(index, value int) {
	seg.bucket[0][index] = value
	for seg.i = 0; seg.i < seg.h-1; seg.i++ {
		s := index - index%seg.chunk
		t := s + seg.chunk
		if t > len(seg.bucket[seg.i]) {
			t = len(seg.bucket[seg.i])
		}
		parent := index / seg.chunk
		min := seg.inf
		for i := s; i < t; i++ {
			if min > seg.bucket[seg.i][i] {
				min = seg.bucket[seg.i][i]
			}
		}
		seg.bucket[seg.i+1][parent] = min
		index /= seg.chunk
	}
}

func (seg *Segment) top() int {
	index := 0
	for seg.i = seg.h - 2; seg.i >= 0; seg.i-- {
		s := index * seg.chunk
		t := s + seg.chunk
		if t > len(seg.bucket[seg.i]) {
			t = len(seg.bucket[seg.i])
		}
		for i := s; i < t; i++ {
			if seg.bucket[seg.i][i] == seg.bucket[seg.i+1][index] {
				index = i
				break
			}
		}
	}
	return index
}


Measured memory_bytes: 6016