#ifdef ONPC
    #define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>

using namespace std;

#define all(v) begin(v), end(v)

using ll = long long;

void test_case() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
    }
    vector<int> p(n);
    for (auto &i : p) {
        cin >> i;
    }

    ll ans = 0, cur = 0;
    for (int i = 0; i < n; ++i) {
        cur += a[i];
        if (cur >= ans) {
            ans = cur;
        }
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
//    cin >> t;
    while (t--) {
        test_case();
    }

    return 0;
}
