from collections import defaultdict

from bisect import bisect_right



S = eval(input())

T = eval(input())



s_set = set(list(S))

t_set = set(list(T))



if not t_set <= s_set:

    print((-1))

    exit()





s_position = defaultdict(list)

for i, s in enumerate(S):

    s_position[s].append(i)





now_position = -1

t_position = [-1] * len(T)

for i, t in enumerate(T):

    ti = bisect_right(s_position[t], now_position)

    if ti >= len(s_position[t]):

        ti = 0



    t_position[i] = s_position[t][ti]

    now_position = s_position[t][ti]



ans = 0

for i in range(len(T) - 1):

    if t_position[i] >= t_position[i + 1]:

        ans += len(S)



print((ans + t_position[-1] + 1))

from collections import defaultdict

from bisect import bisect_right

S = eval(input())

T = eval(input())

NS = len(S)



# 構成不可

if set(list(T)) - set(list(S)):

    print((-1))

    exit()





# 各文字の出現場所を記録

D = defaultdict(list)

for i, s in enumerate(S):

    D[s].append(i)





ans = 0

marker = -1

for t in T:

    target_char_appeared_indexes = D[t]

    bi = bisect_right(target_char_appeared_indexes, marker)

    # もう一周してこないと見つけられない

    if bi == len(target_char_appeared_indexes):

        ans += NS

        marker = target_char_appeared_indexes[0]

    else:

        marker = target_char_appeared_indexes[bi]





# 0-indexedのため+1

print((ans + marker + 1))

from collections import defaultdict
from bisect import bisect_right

S = eval(input())
T = eval(input())
s_set = set(list(S))
t_set = set(list(T))
if not t_set <= s_set:
    print((-1))
    exit()
s_position = defaultdict(list)
for i, s in enumerate(S):
    s_position[s].append(i)
now_position = -1
t_position = [-1] * len(T)
for i, t in enumerate(T):
    ti = bisect_right(s_position[t], now_position)
    if ti >= len(s_position[t]):
        ti = 0
    t_position[i] = s_position[t][ti]
    now_position = s_position[t][ti]
ans = 0
for i in range(len(T) - 1):
    if t_position[i] >= t_position[i + 1]:
        ans += len(S)
print((ans + t_position[-1] + 1))

from collections import defaultdict
from bisect import bisect_right

S = eval(input())
T = eval(input())
NS = len(S)
# 構成不可
if set(list(T)) - set(list(S)):
    print((-1))
    exit()
# 各文字の出現場所を記録
D = defaultdict(list)
for i, s in enumerate(S):
    D[s].append(i)
ans = 0
marker = -1
for t in T:
    target_char_appeared_indexes = D[t]
    bi = bisect_right(target_char_appeared_indexes, marker)
    # もう一周してこないと見つけられない
    if bi == len(target_char_appeared_indexes):
        ans += NS
        marker = target_char_appeared_indexes[0]
    else:
        marker = target_char_appeared_indexes[bi]
# 0-indexedのため+1
print((ans + marker + 1))

-s_set = set(list(S)) -t_set = set(list(T)) -if not t_set <= s_set: +NS = len(S) +# 構成不可 +if set(list(T)) - set(list(S)): -s_position = defaultdict(list) +# 各文字の出現場所を記録 +D = defaultdict(list) -    s_position[s].append(i) -now_position = -1 -t_position = [-1] * len(T) -for i, t in enumerate(T): -    ti = bisect_right(s_position[t], now_position) -    if ti >= len(s_position[t]): -        ti = 0 -    t_position[i] = s_position[t][ti] -    now_position = s_position[t][ti] +    D[s].append(i) -for i in range(len(T) - 1): -    if t_position[i] >= t_position[i + 1]: -        ans += len(S) -print((ans + t_position[-1] + 1)) +marker = -1 +for t in T: +    target_char_appeared_indexes = D[t] +    bi = bisect_right(target_char_appeared_indexes, marker) +    # もう一周してこないと見つけられない +    if bi == len(target_char_appeared_indexes): +        ans += NS +        marker = target_char_appeared_indexes[0] +    else: +        marker = target_char_appeared_indexes[bi] +# 0-indexedのため+1 +print((ans + marker + 1))