/* a */
#include <bits/stdc++.h>
#define N 55

using namespace std;

int n, t[N];
string s[N], X;

int main() {
	cin >> n;	
	for(int i = 1; i <= n; ++i)
		cin >> s[i] >> t[i];
	cin >> X;
	int ans = 0;
	for(int i = n; i >= 1; --i) {
		if(s[i] == X) break;
		ans += t[i];
	}
	cout << ans << endl;
	return 0;
}