function main(input){
    var input = input.split('\n');
    var num = parseInt(input[0]);
    var playlist = Array(num);
    var log = Array(num);
    var flag = 0;
    var time = 0;

    for(i=1;i<=num;i++){
        playlist[i] = input[i].split(' ');
        if(flag==1){
            time=time+parseInt(playlist[i][1]);
        }
        if(playlist[i][0] == input[num+1]){
            flag=1;
        }
    }

    console.log(time);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));