#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <array>
using namespace std;
using ll = long long;
#define all(x) x.begin(),x.end()

const ll INF = 1e16;

vector<ll> a, b;
vector<vector<ll>> dp;

void solve() {
	int n;
	cin >> n;
	a.resize(n);
	b.resize(n);
	//dp.resize(n + 1, vector<ll>(n, -INF));
	for (int i = 0; i < n; i++)
	{
		cin >> a[i] >> b[i];
	}
	vector<int> p(n);
	int mx = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> p[i];
		mx = max(mx, p[i]);
	}
	ll sum = 0, ans = 0;
	for (int i = 0; i < n; i++)
	{
		sum += a[i];
		ans = max(ans, sum);
	}
	cout << ans;

}

int main()
{
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
#endif // _DEBUG
	ios::sync_with_stdio(0);
	cin.tie(0);
	solve();
}

