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

alias Pair = Tuple!(long, "p", int, "r");


void main() {
    int n;
    scan(n);

    auto x = new long[](n + 1);
    auto s = new int[](n + 1);

    foreach (i ; 1 .. n + 1) {
        scan(x[i], s[i]);
    }

    auto mh = MaxHeap!(Pair)(n);
    long d;
    long p = s[1];
    long ans = p;

    mh.push(Pair(s[1], 1));

    foreach (i ; 2 .. n + 1) {
        p += s[i] - (x[i] - x[i-1]);
        mh.push(Pair(p, i));
        ans = max(ans, p);
    }

    foreach (i ; 1 .. n) {
        d += x[i + 1] - x[i] - s[i];

        while (mh.front.r <= i) {
            mh.pop;
        }

        debug {
            writeln(d);
            writeln(mh.front);
        }

        ans = max(ans, mh.front.p + d);
    }

    writeln(ans);
}


struct MaxHeap(T) {
    private {
        int N, last;
        T[] data;
    }

    this(int n) {
        N = n;
        data = new T[](N);
        last = 0;
    }

    bool empty() {
        return last == 0;
    }

    bool full() {
        return last == N;
    }

    T front() {
        return data[0];
    }

    void heapUp(int x) {
        while (x > 0) {
            if (data[x] > data[(x - 1) / 2]) {
                swap(data[x], data[(x - 1) / 2]);
                x = (x - 1) / 2;
            }
            else {
                break;
            }
        }
    }

    void heapDown(int x) {
        while (2*x + 1 < last) {
            int ch = 2*x + 1;

            if (2*x + 2 < last && data[2*x + 2] > data[2*x + 1]) {
                ch = 2*x + 2;
            }

            if (data[ch] > data[x]) {
                swap(data[ch], data[x]);
                x = ch;
            }
            else {
                break;
            }
        }
    }

    void push(T x) {
        assert(!full);
        data[last++] = x;
        heapUp(last - 1);
    }

    void pop() {
        assert(!empty);
        data[0] = data[last - 1];
        last--;
        heapDown(0);
    }

    T[] array() {
        return data[0 .. last];
    }
}

unittest {
    auto mh = MaxHeap!(int)(5);

    mh.push(3);
    mh.push(1);
    mh.push(4);
    mh.push(5);
    mh.push(1);

    assert(mh.full);
    assert(mh.front == 5);

    mh.pop;
    mh.pop;
    mh.pop;

    assert(mh.front == 1);
}

void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}