let () =
  Scanf.scanf "%d\n" @@ fun n ->
  let pair = Array.init n @@ fun _ -> Scanf.scanf "%s %d\n" @@ fun s t -> (s, t) in
  Scanf.scanf "%s\n" @@ fun x ->
  let sum = Array.fold_left (fun sum p -> sum + snd p) 0 pair in
  let listen = Array.fold_left
      (fun (sum, b) p -> if fst p = x then (sum + snd p, true) else if b then (sum, b) else (sum + snd p, b))
      (0, false) pair  in
  Printf.printf "%d\n" (sum - fst listen)