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



import std.conv;
import std.range;
import std.stdio;

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

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto s = input.front.to!( dchar[] );
	input.popFront;
	auto t = input.front.to!( dchar[] );
	
	// 現在位置から何の文字が何文字後にあるかのテーブルを作成
	auto css = new long[][]( s.length * 2 + 1, 26 );
	foreach_reverse( i, c; s ~ s )
	{
		foreach( j; 0 .. 26 )
		{
			auto ci = c - 'a';
			css[ i ][ j ] = ( j == ci ) ? 1 : css[ i + 1 ][ j ] + 1;
		}
	}
	
	// 部分列の長さを判定
	auto ans = 0L;
	foreach( c; t )
	{
		auto ci = c - 'a';
		if( s.length < css[ 0 ][ ci ] ) return -1;
		ans += css[ ans % s.length ][ ci ];
	}
	return ans;
}
