import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main() {
  auto n = readln.strip.to!int;
  Tuple!(string, int)[] a;
  foreach (i; 0 .. n) {
    auto s = readln.splitter;
    auto z = s.front;
    s.popFront ();
    a ~= tuple (z, s.front.to!int);
  }
  auto t = readln.strip;
  int res;
  foreach_reverse (i; 0 .. n) {
    if (a[i][0] == t) break;
    res += a[i][1];
  }
  writeln (res);
}

