
// Problem : A - Falling Asleep
// Contest : Dwango Programming Contest 6th
// URL : https://atcoder.jp/contests/dwacon6th-prelims/tasks/dwacon6th_prelims_a
// Memory Limit : 1024.000000 MB 
// Time Limit : 2525.000000 milisec 
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define int long long
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr);

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
		
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1000000007;
const int INF = 1e18;
const int N = (int)3e5+5;

int32_t main()
{
	IOS;
	int n;
	cin >> n;
	vector<pair<string, int>> v;
	for(int i = 0; i < n; i++)
	{
		string s;
		int x;
		cin >> s >> x;
		v.push_back({s, x});
	}
	bool flag = false;
	string tar; cin >> tar;
	int cnt = 0;
	for(auto it : v)
	{
		string x = it.first;
		int  y = it.second;
		if(flag)
			cnt += y;
		if(x == tar)
			flag = true;
	}
	cout << cnt;
 	return 0;
}
