from bisect import bisect_left as bisect

from collections import defaultdict





s, t = eval(input()), eval(input())

lens, sets = len(s), set(s)



if not all(i in sets for i in t):

    print((-1))

    exit()



alp = defaultdict(list)

for i, si in enumerate(s):

    alp[si].append(i)



ans, cnt = 1 - lens, 0

for i in t:

    ans += lens * (cnt == 0)

    num = bisect(alp[i], cnt)

    ans += lens * (num == len(alp[i]))

    cnt = (alp[i][num % len(alp[i])] + 1) % lens 

print((ans + (cnt - 1) % lens))

from bisect import bisect_left as bisect



s, t = eval(input()), eval(input())

lens, sets = len(s), set(s)



if not all(i in sets for i in t):

    print((-1))

    exit()



alp = [[] for i in range(26)]

for i, si in enumerate(s):

    alp[ord(si) - 97].append(i)



ans, cnt = 1 - lens, 0

for i in t:

    li = alp[ord(i) - 97]

    ans += lens * (cnt == 0)

    num = bisect(li, cnt)

    ans += lens * (num == len(li))

    cnt = (li[num % len(li)] + 1) % lens 

print((ans + (cnt - 1) % lens))

from bisect import bisect_left as bisect
from collections import defaultdict

s, t = eval(input()), eval(input())
lens, sets = len(s), set(s)
if not all(i in sets for i in t):
    print((-1))
    exit()
alp = defaultdict(list)
for i, si in enumerate(s):
    alp[si].append(i)
ans, cnt = 1 - lens, 0
for i in t:
    ans += lens * (cnt == 0)
    num = bisect(alp[i], cnt)
    ans += lens * (num == len(alp[i]))
    cnt = (alp[i][num % len(alp[i])] + 1) % lens
print((ans + (cnt - 1) % lens))

from bisect import bisect_left as bisect

s, t = eval(input()), eval(input())
lens, sets = len(s), set(s)
if not all(i in sets for i in t):
    print((-1))
    exit()
alp = [[] for i in range(26)]
for i, si in enumerate(s):
    alp[ord(si) - 97].append(i)
ans, cnt = 1 - lens, 0
for i in t:
    li = alp[ord(i) - 97]
    ans += lens * (cnt == 0)
    num = bisect(li, cnt)
    ans += lens * (num == len(li))
    cnt = (li[num % len(li)] + 1) % lens
print((ans + (cnt - 1) % lens))

-from collections import defaultdict -alp = defaultdict(list) +alp = [[] for i in range(26)] -    alp[si].append(i) +    alp[ord(si) - 97].append(i) +    li = alp[ord(i) - 97] -    num = bisect(alp[i], cnt) -    ans += lens * (num == len(alp[i])) -    cnt = (alp[i][num % len(alp[i])] + 1) % lens +    num = bisect(li, cnt) +    ans += lens * (num == len(li)) +    cnt = (li[num % len(li)] + 1) % lens