from bisect import *



S = eval(input())

T = eval(input())



ds = {}

for i,s in enumerate(S) :

    if s not in ds :

        ds[s] = [i]

    else :

        ds[s].append(i)

L = []

ind = -1

flg = 0

cnt = 0

for t in T :

    if t not in ds :

        ans = -1

        flg = 1

        break

if flg == 0 :

    for t in T :

        if ind >= ds[t][-1] :

            ind = ds[t][0]

            L.append(ind)

            cnt += 1

        else :

            ind = ds[t][bisect_right(ds[t], ind)]

            L.append(ind)

    ans = cnt * len(S) + L[-1] + 1

"""

    cnt = 0

    val = L[0]

    for i in range(1,len(L)) :

        if val >= L[i] :

            val = L[i]

            cnt += 1

"""

    

print(ans)
from bisect import *

S = eval(input())

T = eval(input())

ds = {}

for i,s in enumerate(S) :

    if s not in ds :

        ds[s] = [i]

    else :

        ds[s].append(i)



ind = -1

cnt = 0



for t in T :

    if t not in ds :

        ans = -1

        break

else :

    for t in T :

        if ds[t][-1] <= ind :

            ind = ds[t][0]

            cnt += 1

        else :

            ind = ds[t][bisect_right(ds[t], ind)]

    ans = cnt * len(S) + ind + 1

print(ans)

from bisect import *

S = eval(input())
T = eval(input())
ds = {}
for i, s in enumerate(S):
    if s not in ds:
        ds[s] = [i]
    else:
        ds[s].append(i)
L = []
ind = -1
flg = 0
cnt = 0
for t in T:
    if t not in ds:
        ans = -1
        flg = 1
        break
if flg == 0:
    for t in T:
        if ind >= ds[t][-1]:
            ind = ds[t][0]
            L.append(ind)
            cnt += 1
        else:
            ind = ds[t][bisect_right(ds[t], ind)]
            L.append(ind)
    ans = cnt * len(S) + L[-1] + 1
"""
    cnt = 0
    val = L[0]
    for i in range(1,len(L)) :
        if val >= L[i] :
            val = L[i]
            cnt += 1
"""
print(ans)

from bisect import *

S = eval(input())
T = eval(input())
ds = {}
for i, s in enumerate(S):
    if s not in ds:
        ds[s] = [i]
    else:
        ds[s].append(i)
ind = -1
cnt = 0
for t in T:
    if t not in ds:
        ans = -1
        break
else:
    for t in T:
        if ds[t][-1] <= ind:
            ind = ds[t][0]
            cnt += 1
        else:
            ind = ds[t][bisect_right(ds[t], ind)]
    ans = cnt * len(S) + ind + 1
print(ans)

-L = [] -flg = 0 -        flg = 1 -if flg == 0: +else: -        if ind >= ds[t][-1]: +        if ds[t][-1] <= ind: -            L.append(ind) -            L.append(ind) -    ans = cnt * len(S) + L[-1] + 1 -""" -    cnt = 0 -    val = L[0] -    for i in range(1,len(L)) : -        if val >= L[i] : -            val = L[i] -            cnt += 1 -""" +    ans = cnt * len(S) + ind + 1