/**
 * @param input string[]
 */
function Main(input) {
  const songs = input.slice(1, -1).map((line) => line.split(' '));
  const X = input[input.length - 1];

  var i = 0;
  var XIndex;
  while (true) {
    if (songs[i][0] === X) {
      XIndex = i;
      break;
    }
    i++;
  }

  const answer = songs.slice(XIndex + 1).reduce((pv, cv) => {
    return pv + (+cv[1]);
  }, 0);

  console.log(answer);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim()
  .split('\n')
);
