#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using Graph = vector<vector<long long>>;
signed main() {
  long long a;
  cin >> a;
  vector<string> b(a);
  vector<long long> c(a);
  for (long long i = 0; i < a; i++) cin >> b[i] >> c[i];
  string d;
  cin >> d;
  long long e = 0;
  bool f = false;
  for (long long i = 0; i < a; i++) {
    if (f) e += c[i];
    if (d == b[i]) f = true;
  }
  cout << e << endl;
}
