open Printf
open Scanf

let () =
  let n = scanf "%d " (fun x -> x) in
  let ar = Array.init n (fun _ -> scanf "%s %d " (fun x y -> (x, y))) in
  let (_, db) = Array.fold_right (fun (nm, t) (tt, ls) -> (t + tt, (nm, tt) :: ls)) ar (0, []) in
  let s = scanf "%s " (fun x -> x) in
  printf "%d\n" @@ List.assoc s db
