#include <iostream>
#include <string>
using namespace std;
string s[60],x;
int t[60];
int main(){
	int i,n,sum = 0;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> s[i] >> t[i];
	}
	cin >> x;
	int j = -1;
	for(i=0;i<n;i++){
		if(x==s[i]){
			j = i;
			break;
		}
	}
	for(i=j + 1;i<n;i++){
		sum += t[i];
	}
	cout << sum << endl;
}
			