#include <iostream>
#include <utility>
using namespace std;

int main()
{
    pair<int, int>* arr;
    int N, m, curr_sum = 0, ans = 0;

    cin >> N;
    arr = new pair<int, int>[N];

    for (int i = 0; i < N; i++)
        cin >> arr[i].first >> arr[i].second;

    for (int i = 0; i < N; i++)
    {
        m = arr[i].second;
        ans += curr_sum;

        if (m > 0)
        {
            curr_sum += m;
        }
        else
        {
            curr_sum -= arr[i - 1].second;
        }
    }

    cout << ans << endl;

    return 0;
}
