function main(input) {
  input = input.trim()
  args = input.split('\n');
  text = (args.slice(-1)[0])
  isFlag = false
  ans = 0
  for (var i = 1; i < args.length -1 ; i++){
    baz = args[i].split(' ');
    if (isFlag) {
      ans += parseInt(baz[1], 10)
    }
    if (baz[0] == text) {
      isFlag = true
    }
  }
  console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));