import java.util.*

fun main(args: Array<String>) {
    val N = readLine()!!.toInt()

    val ps = Array(N) { readLine()!!.split(" ").map { it.toLong() } }
        .sortedWith(Comparator { a, b ->
            val c = if (a[1] == b[1]) a[0] - b[0] else a[1] - b[1]
            when {
                c < 0 -> -1
                c > 0 -> 1
                else -> 0
            }
        })

    val ll = ArrayList<Long>()
    val lr = ArrayList<Long>()

    func(ll, lr, ps)

    val rl = ArrayList<Long>()
    val rr = ArrayList<Long>()

    func(rl, rr, ps.reversed())

    rl.reverse()
    rr.reverse()

    var res = 0L

    for (i in 1 until N - 1) {
        val v0 = Math.max(lr[i] - ll[i] + 1, 0L)
        val v1 = Math.max(rr[i] - rl[i] + 1, 0L)

        res = Math.max(
            res,
            v0 + v1
        )
    }

    for (i in 0 until N) {
        val t = Math.min(lr[i], rr[i + 1]) - Math.max(ll[i], rl[i + 1]) + 1
        res = Math.max(
            res,
            ps[i][1] - ps[i][0] + 1 + Math.max(t, 0L)
        )
    }

    println(res)
}

private fun func(
    left: ArrayList<Long>,
    right: ArrayList<Long>,
    ps: List<List<Long>>
) {
    left.add(1)
    right.add(1e9.toLong())

    for (l in ps) {
        left.add(Math.max(left.last(), l[0]))
        right.add(Math.min(right.last(), l[1]))
    }
}

private fun slow(N: Int, ps: List<List<Long>>): Long {
    var res = 0L
    for (i in 1 until (1 shl N) - 1) {
        val a = ps.filterIndexed { index, list -> (i shr index) and 1 == 1 }
        val b = ps.filterIndexed { index, list -> (i shr index) and 1 == 0 }

        val v0 = Math.max(a.map { it[1] }.min()!! - a.map { it[0] }.max()!! + 1, 0L)
        val v1 = Math.max(b.map { it[1] }.min()!! - b.map { it[0] }.max()!! + 1, 0L)

        res = Math.max(res, v0 + v1)

        if (v0 + v1 == 540049931L) {
            System.out.printf("%x\n", i)
        }
    }
    return res
}
