unittest
{
	assert( [ "contest", "son" ].parse.expand.solve == 10 );
	assert( [ "contest", "programming" ].parse.expand.solve == -1 );
	assert( [ "contest", "sentence" ].parse.expand.solve == 33 );
}



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 s = input.front.to!( dchar[] );
	input.popFront;
	auto t = input.front.to!( dchar[] );
	return tuple( s, t );
}

auto solve( dchar[] s, dchar[] t )
{
	auto dp = new long[][]( 26, s.length );
	foreach( ref dpp; dp ) dpp[] = -1;
	for( auto ci = 0L; ci < 26; ci++ )
	{
		auto c = cast( dchar )( 'a' + ci );
		foreach_reverse( si, sc; s )
		{
			if( sc == c )
			{
				dp[ ci ][ si ] = 1;
			}
			else if( si + 1 < dp[ ci ].length && 0 < dp[ ci ][ si + 1 ] )
			{
				dp[ ci ][ si ] = dp[ ci ][ si + 1 ] + 1;
			}
		}
	}
	
	auto ans = 0L;
	foreach( tc; t )
	{
		auto si = ans % s.length;
		auto ci = cast( long )( tc - 'a' );
		
		if( 0 <= dp[ ci ][ si ] )
		{
			ans += dp[ ci ][ si ];
		}
		else
		{
			if( dp[ ci ][ 0 ] == -1 ) return -1;
			ans += s.length.signed - si + dp[ ci ][ 0 ];
		}
	}
	return ans;
}
