#include <bits/stdc++.h>
using namespace std;

int main()
{
	long long N;
	cin >> N;
	vector<string> s( N );
	vector<int> t( N );
	for( int i = 0; i < N; i++ ) {
		cin >> s[i] >> t[i];
	}
	string X;
	cin >> X;

	int ans = 0;
	int flag = 0;
	for( int i = 0; i < N; i++ ) {
		if( flag ) ans += t[i];
		if( s[i] == X ) flag = 1;
		
	}

	cout << ans << endl;
}
