from collections import defaultdict

from bisect import bisect_right



s,t=eval(input()),eval(input())

m=len(s)



if set(s)&set(t)!=set(t):print((-1));exit()



dict=defaultdict(list)

for i,j in enumerate(s):

    dict[j] +=[i+1]



ans,index=0,0

for i in t:

    point=bisect_right(dict[i],index)

    if point==len(dict[i]):num=dict[i][0]

    else:num=dict[i][point]



    if index>=num:

        ans +=m

    index=num



print((ans+index))
from collections import defaultdict

from bisect import bisect_right

s,t=eval(input()),eval(input())

m=len(s)



dictionary=defaultdict(list)

for i,j in enumerate(s):

    dictionary[j] +=[i+1]



index,ans=0,0

for i in t:

    try:

        point=bisect_right(dictionary[i],index)

        if point==len(dictionary[i]):num=dictionary[i][0]

        else:num=dictionary[i][point]



        if index>=num:

            ans +=m

        index=num

    except:print((-1));exit()



print((ans+index))
from collections import defaultdict
from bisect import bisect_right

s, t = eval(input()), eval(input())
m = len(s)
if set(s) & set(t) != set(t):
    print((-1))
    exit()
dict = defaultdict(list)
for i, j in enumerate(s):
    dict[j] += [i + 1]
ans, index = 0, 0
for i in t:
    point = bisect_right(dict[i], index)
    if point == len(dict[i]):
        num = dict[i][0]
    else:
        num = dict[i][point]
    if index >= num:
        ans += m
    index = num
print((ans + index))

from collections import defaultdict
from bisect import bisect_right

s, t = eval(input()), eval(input())
m = len(s)
dictionary = defaultdict(list)
for i, j in enumerate(s):
    dictionary[j] += [i + 1]
index, ans = 0, 0
for i in t:
    try:
        point = bisect_right(dictionary[i], index)
        if point == len(dictionary[i]):
            num = dictionary[i][0]
        else:
            num = dictionary[i][point]
        if index >= num:
            ans += m
        index = num
    except:
        print((-1))
        exit()
print((ans + index))

-if set(s) & set(t) != set(t): -    print((-1)) -    exit() -dict = defaultdict(list) +dictionary = defaultdict(list) -    dict[j] += [i + 1] -ans, index = 0, 0 +    dictionary[j] += [i + 1] +index, ans = 0, 0 -    point = bisect_right(dict[i], index) -    if point == len(dict[i]): -        num = dict[i][0] -    else: -        num = dict[i][point] -    if index >= num: -        ans += m -    index = num +    try: +        point = bisect_right(dictionary[i], index) +        if point == len(dictionary[i]): +            num = dictionary[i][0] +        else: +            num = dictionary[i][point] +        if index >= num: +            ans += m +        index = num +    except: +        print((-1)) +        exit()