function Main(input){
  input = input.split("\n");
  const N = input.shift();
  const X = input.pop();
  input = input.map(val=>val.split(" "));
  var a = N;
  var result = 0;
  for(var n = 0; n < N; n++){
    if(X == input[n][0]) a = n;
    if(a < n) result += Number(input[n][1]);
  }
  console.log(result);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));