#include <bits/stdc++.h>

#define int long long
// #pragma GCC optimize("O3")
// // #pragma GCC optimize("Ofast")
// // #pragma GCC target("unroll_loops")

using ll = long long;
using ld = long double;
using namespace std;

// #include <ext/pb_ds/assoc_container.hpp>

//  using namespace __gnu_pbds;
// using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;

const int INF = 1e18, MAXN = 5010, mod = 998244353;

int binpow(int a, int b) {
    if (b == 0) {
        return 1;
    }
    int aa = binpow(a, b / 2);
    if (b % 2 == 0) {
        return (aa * aa) % mod;
    }
    return ((aa * aa) % mod * a) % mod;
}

void solve();

signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int tt = 1;
    //cin >> tt;
    while (tt--) {
        solve();
        cout << "\n";
    }
}


void solve() {
    int n;
    cin >> n;
    vector<int> p(n);
    vector<pair<int,int> > arr(n);\
    vector<int> pref_a(n + 1);
    for (int i = 0; i < n; i++) {
        cin >> arr[i].first >> arr[i].second;
        pref_a[i + 1] = pref_a[i] + arr[i].first;
    }
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    vector<vector<int> > dp(n + 1, vector<int>(n + 1, -INF));
    int ans = 0;
    int sm = 0;
    for (int i = 0; i < n; i++) {
        ans = max(ans, sm);
        sm += arr[i].first;
    }
    cout << ans;
}
