#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>


// order_of_key
// find_by_order
using namespace __gnu_pbds;
using namespace std;
using ll = long long;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;





int main() {
	ll n; cin >> n;

	vector <pair <ll, ll>> vec(n + 1);
	for (ll i = 1; i <= n; i++) cin >> vec[i].first >> vec[i].second;


	vector <ll> p(n + 1);
	for (ll i = 1; i <= n; i++) cin >> p[i];




	ll ans = 0;
	ll cur = 0;

	for (ll i = 1; i <= n; i++) {
		cur += vec[i].first;
		ans = max(ans, cur);
	}


	cout << ans << endl;
}