from collections import defaultdict

import bisect





S = eval(input())

T = eval(input())



if set(T) - set(S):

    print((-1))

    exit()



dic = defaultdict(list)

leng_dic = defaultdict(int)



for pos, s in enumerate(S):

    dic[s].append(pos)

    leng_dic[s] += 1



length = len(S)

now = -1

count = 0

for t in T:

    if dic[t][-1] < now+1:

        now = -1

        count += 1

    idx = bisect.bisect_left(dic[t], now+1)

    now = dic[t][idx]



ans = count*length + now + 1

print(ans)
from collections import defaultdict

import bisect





S = eval(input())

T = eval(input())



if set(T) - set(S):

    print((-1))

    exit()



dic = defaultdict(list)

for pos, s in enumerate(S):

    dic[s].append(pos)



now = -1

count = 0

for t in T:

    if dic[t][-1] < now+1:

        now = -1

        count += 1

    idx = bisect.bisect_left(dic[t], now+1)

    now = dic[t][idx]



ans = count*len(S) + now + 1

print(ans)
from collections import defaultdict
import bisect

S = eval(input())
T = eval(input())
if set(T) - set(S):
    print((-1))
    exit()
dic = defaultdict(list)
leng_dic = defaultdict(int)
for pos, s in enumerate(S):
    dic[s].append(pos)
    leng_dic[s] += 1
length = len(S)
now = -1
count = 0
for t in T:
    if dic[t][-1] < now + 1:
        now = -1
        count += 1
    idx = bisect.bisect_left(dic[t], now + 1)
    now = dic[t][idx]
ans = count * length + now + 1
print(ans)

from collections import defaultdict
import bisect

S = eval(input())
T = eval(input())
if set(T) - set(S):
    print((-1))
    exit()
dic = defaultdict(list)
for pos, s in enumerate(S):
    dic[s].append(pos)
now = -1
count = 0
for t in T:
    if dic[t][-1] < now + 1:
        now = -1
        count += 1
    idx = bisect.bisect_left(dic[t], now + 1)
    now = dic[t][idx]
ans = count * len(S) + now + 1
print(ans)

-leng_dic = defaultdict(int) -    leng_dic[s] += 1 -length = len(S) -ans = count * length + now + 1 +ans = count * len(S) + now + 1