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

int main()
{
	ll n;
	cin>>n;
	string s[n];
	ll a[n],i;
	for(i=0;i<n;i++)
	{
		cin>>s[i]>>a[i];
	}
	string b;
	cin>>b;
	ll p=0,f=0;
	for(i=0;i<n;i++)
	{
		if(f==-1)
			p+=a[i];
		if(s[i]==b)
		{
			f=-1;
		}
	}
	cout<<p<<"\n";
}