#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <climits>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <vector>
#pragma GCC optimize("Ofast")
using namespace std;
using ll = long long;
using ld = long double;
const ll maxn = 5'000, mod = 998'244'353;
int main() {
	ll n; cin >> n;
	vector<pair<int, int>> a(n);
	bool f = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a[i].first >> a[i].second;
		if (a[i].second > 0) {
			f = 1;
		}
	}
	vector<int> p(n);
	bool f1 = 0;
	for (int i = 0; i < n; ++i) {
		cin >> p[i];
		if (p[i] != -1) f1 = 1;
	}
	ll ans = 0;
	ll cur = 0, curb = 0;
	for (int i = 0; i < n; ++i) {
		ans = max(cur, ans);
		cur += a[i].first;
		ans = max(cur, ans);
	}
	if (f)
		cout << ans;

}