from bisect import bisect_left



s = eval(input())

t = eval(input())



l = len(s)



ss = s * 2

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

for i, e in enumerate(ss, 1):

    idx = ord(e) - ord("a")

    let[idx].append(i)



for e in t:

    idx = ord(e) - ord("a")

    if not let[idx]:

        print((-1))

        exit()



i = 1

times = 0

for e in t:

    j = ord(e) - ord("a")

    choose = bisect_left(let[j], i)

    q, r = divmod(let[j][choose], l)

    times += q

    i = r + 1



ans = times * l + i - 1

print(ans)

from collections import Counter, defaultdict

from bisect import bisect_right



s = eval(input())

t = eval(input())



c = Counter(s)

for e in t:

    if c[e] == 0:

        print((-1))

        exit()



ss = s + s

d = defaultdict(list)

for i, e in enumerate(ss):

    d[e].append(i)



now = -1

ans = 0

for e in t:

    i = bisect_right(d[e], now)

    nxt = d[e][i]

    ans += nxt - now

    now = nxt % len(s)



print(ans)

from bisect import bisect_left

s = eval(input())
t = eval(input())
l = len(s)
ss = s * 2
let = [[] for _ in range(26)]
for i, e in enumerate(ss, 1):
    idx = ord(e) - ord("a")
    let[idx].append(i)
for e in t:
    idx = ord(e) - ord("a")
    if not let[idx]:
        print((-1))
        exit()
i = 1
times = 0
for e in t:
    j = ord(e) - ord("a")
    choose = bisect_left(let[j], i)
    q, r = divmod(let[j][choose], l)
    times += q
    i = r + 1
ans = times * l + i - 1
print(ans)

from collections import Counter, defaultdict
from bisect import bisect_right

s = eval(input())
t = eval(input())
c = Counter(s)
for e in t:
    if c[e] == 0:
        print((-1))
        exit()
ss = s + s
d = defaultdict(list)
for i, e in enumerate(ss):
    d[e].append(i)
now = -1
ans = 0
for e in t:
    i = bisect_right(d[e], now)
    nxt = d[e][i]
    ans += nxt - now
    now = nxt % len(s)
print(ans)

-from bisect import bisect_left +from collections import Counter, defaultdict +from bisect import bisect_right -l = len(s) -ss = s * 2 -let = [[] for _ in range(26)] -for i, e in enumerate(ss, 1): -    idx = ord(e) - ord("a") -    let[idx].append(i) +c = Counter(s) -    idx = ord(e) - ord("a") -    if not let[idx]: +    if c[e] == 0: -i = 1 -times = 0 +ss = s + s +d = defaultdict(list) +for i, e in enumerate(ss): +    d[e].append(i) +now = -1 +ans = 0 -    j = ord(e) - ord("a") -    choose = bisect_left(let[j], i) -    q, r = divmod(let[j][choose], l) -    times += q -    i = r + 1 -ans = times * l + i - 1 +    i = bisect_right(d[e], now) +    nxt = d[e][i] +    ans += nxt - now +    now = nxt % len(s)