unittest
{
	assert( [ "3", "dwango 2", "sixth 5", "prelims 25", "dwango" ].parse.expand.solve == 30 );
	assert( [ "1", "abcde 1000", "abcde" ].parse.expand.solve == 0 );
	assert( [ "15", "ypnxn 279", "kgjgwx 464", "qquhuwq 327", "rxing 549", "pmuduhznoaqu 832", "dagktgdarveusju 595", "wunfagppcoi 200", "dhavrncwfw 720", "jpcmigg 658", "wrczqxycivdqn 639", "mcmkkbnjfeod 992", "htqvkgkbhtytsz 130", "twflegsjz 467", "dswxxrxuzzfhkp 989", "szfwtzfpnscgue 958", "pmuduhznoaqu" ].parse.expand.solve == 6348 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	auto sts = new Tuple!( dchar[], long )[ n ];
	foreach( ref st; sts )
	{
		input.popFront;
		auto z = input.front.split;
		st[ 0 ] = z[ 0 ].to!( dchar[] );
		st[ 1 ] = z[ 1 ].to!( long );
	}
	input.popFront;
	auto x = input.front.to!( dchar[] );
	return tuple( sts, x );
}

auto solve( Tuple!( dchar[], long )[] sts, dchar[] x )
{
	sts = sts.find!( ( a, b ) => a[ 0 ] == b )( x );
	sts.popFront;
	return reduce!( ( a, b ) => a + b[ 1 ] )( 0L, sts );
}
