import sys

import numpy as np

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

sys.setrecursionlimit(500000)



n = int(readline())

S = []

T = []

for i in range(n):

    s, t = readline().decode('utf-8').split()

    t = int(t)

    S.append(s)

    T.append(t)

X = readline().decode('utf-8').split()[0]



idx = S.index(X)

res = sum(T[idx+1:])



print(res)

import sys

import numpy as np

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

sys.setrecursionlimit(500000)



N = int(readline())

ST = [readline().split() for _ in range(N)]

X = read().rstrip()



S, T = list(zip(*ST))



idx = S.index(X)

res = sum(map(int, T[idx+1:]))



print(res)

import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)
n = int(readline())
S = []
T = []
for i in range(n):
    s, t = readline().decode("utf-8").split()
    t = int(t)
    S.append(s)
    T.append(t)
X = readline().decode("utf-8").split()[0]
idx = S.index(X)
res = sum(T[idx + 1 :])
print(res)

import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)
N = int(readline())
ST = [readline().split() for _ in range(N)]
X = read().rstrip()
S, T = list(zip(*ST))
idx = S.index(X)
res = sum(map(int, T[idx + 1 :]))
print(res)

-n = int(readline()) -S = [] -T = [] -for i in range(n): -    s, t = readline().decode("utf-8").split() -    t = int(t) -    S.append(s) -    T.append(t) -X = readline().decode("utf-8").split()[0] +N = int(readline()) +ST = [readline().split() for _ in range(N)] +X = read().rstrip() +S, T = list(zip(*ST)) -res = sum(T[idx + 1 :]) +res = sum(map(int, T[idx + 1 :]))