import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

void main() {
    auto N = readln.chomp.to!int;
    auto XS = N.iota.map!(_ => readln.split.map!(to!long).array).array;

    long ans = 0;
    long tmp = 0;
    int r = 0;

    for (int l = 0; l < N; ++l) {
        if (r <= l) {
            r = l;
            tmp = 0;
        } else if (l > 0) {
            tmp -= XS[l-1][1];
            tmp += XS[l][0] - XS[l-1][0];
            //tmp.writeln;
        }

        for (; r < N && XS[r][1] - XS[r][0] + XS[l][0] >= 0; ++r) {
            tmp += XS[r][1] - XS[r][0] + XS[l][0];
            if (r - l >= 2)
                tmp += XS[r-1][0] - XS[l][0];
            ans = max(ans, tmp);
        }
        //writeln(l, " ", r, " ", tmp);
    }

    ans.writeln;
}
