from bisect import bisect_right, bisect_left

s = [ord(i) - ord("a") for i in eval(input())]

t = [ord(i) - ord("a") for i in eval(input())]

index = [[] for _ in range(26)]



for i, x in enumerate(s):

    index[x].append(i)





l_s = len(s)



for x in index:

    if x:

        x.append(x[0] + l_s)



cnt = -1

for r in t:

    seq = index[r]

    if not seq:

        cnt = -2

        break

    i = cnt % l_s

    j = bisect_right(seq, i)

    cnt += seq[j] - i



print((cnt+1))





from bisect import bisect_left

s = eval(input())

t = eval(input())



n = len(s)

s = s * 2





r = {}

for i, v in enumerate(s):

    if v in list(r.keys()):

        r[v].append(i+1)

    else:

        r[v] = [i+1]



now = 0



lt = len(t)

for v in t:

    if v in list(r.keys()):

        index = bisect_left(r[v], now % n + 1)

        tmp = r[v][index]

        now += tmp - now % n

    else:

        print((-1))

        exit()



print(now)
from bisect import bisect_right, bisect_left

s = [ord(i) - ord("a") for i in eval(input())]
t = [ord(i) - ord("a") for i in eval(input())]
index = [[] for _ in range(26)]
for i, x in enumerate(s):
    index[x].append(i)
l_s = len(s)
for x in index:
    if x:
        x.append(x[0] + l_s)
cnt = -1
for r in t:
    seq = index[r]
    if not seq:
        cnt = -2
        break
    i = cnt % l_s
    j = bisect_right(seq, i)
    cnt += seq[j] - i
print((cnt + 1))

from bisect import bisect_left

s = eval(input())
t = eval(input())
n = len(s)
s = s * 2
r = {}
for i, v in enumerate(s):
    if v in list(r.keys()):
        r[v].append(i + 1)
    else:
        r[v] = [i + 1]
now = 0
lt = len(t)
for v in t:
    if v in list(r.keys()):
        index = bisect_left(r[v], now % n + 1)
        tmp = r[v][index]
        now += tmp - now % n
    else:
        print((-1))
        exit()
print(now)

-from bisect import bisect_right, bisect_left +from bisect import bisect_left -s = [ord(i) - ord("a") for i in eval(input())] -t = [ord(i) - ord("a") for i in eval(input())] -index = [[] for _ in range(26)] -for i, x in enumerate(s): -    index[x].append(i) -l_s = len(s) -for x in index: -    if x: -        x.append(x[0] + l_s) -cnt = -1 -for r in t: -    seq = index[r] -    if not seq: -        cnt = -2 -        break -    i = cnt % l_s -    j = bisect_right(seq, i) -    cnt += seq[j] - i -print((cnt + 1)) +s = eval(input()) +t = eval(input()) +n = len(s) +s = s * 2 +r = {} +for i, v in enumerate(s): +    if v in list(r.keys()): +        r[v].append(i + 1) +    else: +        r[v] = [i + 1] +now = 0 +lt = len(t) +for v in t: +    if v in list(r.keys()): +        index = bisect_left(r[v], now % n + 1) +        tmp = r[v][index] +        now += tmp - now % n +    else: +        print((-1)) +        exit() +print(now)