#include <iostream>
#include <fstream>
#include <complex>
#include <vector>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <random>
#include <ext/pb_ds/assoc_container.hpp>

#define iset(t) __gnu_pbds::tree<t, __gnu_pbds::null_type, less<t>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>

#define V vector
#define P pair
#define F first
#define S second

#ifdef LOC
#define $(x) x
#define clog(x) clog << x
#else
#define $(x)
#define clog(x)
#endif

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<int> ci;
typedef complex<ll> cll;
typedef complex<ld> cld;
typedef P<int, int> pi;
typedef P<ll, ll> pll;
typedef V<bool> vb;
typedef V<int> vi;
typedef V<ll> vll;

int n;
V<pll> s;
vi p;

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

    #ifdef STR
    freopen("ti.txt", "r", stdin);
    freopen("tm.txt", "o", stdout);
    #endif

    cin >> n;

    s.resize(n);
    for (auto &x : s) cin >> x.F >> x.S;

    p.resize(n);
    for (auto &x : p) cin >> x;

    ll c = 0;
    ll ans = s[0].F;
    for (auto x : s) {
        c += x.F;
        ans = max(ans, c);
    }
    cout << ans << "\n";

    return 0;
}