#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <deque>
using namespace std;
using ll = long long;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n;
	cin >> n;
	vector<pair<int, int>> a(n);
	for (auto &[x, y] : a)
		cin >> x >> y;
	vector<int> p(n);
	for (auto &v : p)
		cin >> v;

	ll ans = 0;
	ll sum = 0;
	for (auto [x, y] : a) {
		sum += x;
		ans = max(ans, sum);
	}
	cout << ans << "\n";
}
