#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	string s;
	vector<pair<string,long long> >v;
	long long a,ans=0,c=0,sum=0;
	for(int i=0;i<n;i++)
	{
		cin>>s>>a;
		v.push_back({s,a});
		sum+=a;
	}
	cin>>s;
	for(int i=0;i<n;i++)
	{
		c+=v[i].second;
		if(v[i].first==s)
		{
			ans=sum-c;
			break;
		}
	}
	cout<<ans;
	return 0;
}