from collections import defaultdict

import bisect

s = eval(input())

t = eval(input())

dicta = defaultdict(list)

for a,b in enumerate(s):

    dicta[b] += [a]

snow = -1

count = 0

flag = True

for i in t:

    if i not in s:

        flag = False

        break

    nowt = dicta[i]

    snowind = bisect.bisect_right(nowt,snow)

    if snowind == len(nowt):

        count += 1

        snow = nowt[0]

    else:

        snow = nowt[snowind]

if flag:

    print((len(s)*count+snow +1))

else:

    print((-1))

        
from collections import defaultdict

import bisect

s = eval(input())

t = eval(input())

dicta = defaultdict(list)

for a,b in enumerate(s):

    dicta[b] += [a]

snow = -1

count = 0

flag = True

for i in t:

    if not dicta[i]:

        flag = False

        break

    nowt = dicta[i]

    snowind = bisect.bisect_right(nowt,snow)

    if snowind == len(nowt):

        count += 1

        snow = nowt[0]

    else:

        snow = nowt[snowind]

if flag:

    print((len(s)*count+snow +1))

else:

    print((-1))

        
from collections import defaultdict
import bisect

s = eval(input())
t = eval(input())
dicta = defaultdict(list)
for a, b in enumerate(s):
    dicta[b] += [a]
snow = -1
count = 0
flag = True
for i in t:
    if i not in s:
        flag = False
        break
    nowt = dicta[i]
    snowind = bisect.bisect_right(nowt, snow)
    if snowind == len(nowt):
        count += 1
        snow = nowt[0]
    else:
        snow = nowt[snowind]
if flag:
    print((len(s) * count + snow + 1))
else:
    print((-1))

from collections import defaultdict
import bisect

s = eval(input())
t = eval(input())
dicta = defaultdict(list)
for a, b in enumerate(s):
    dicta[b] += [a]
snow = -1
count = 0
flag = True
for i in t:
    if not dicta[i]:
        flag = False
        break
    nowt = dicta[i]
    snowind = bisect.bisect_right(nowt, snow)
    if snowind == len(nowt):
        count += 1
        snow = nowt[0]
    else:
        snow = nowt[snowind]
if flag:
    print((len(s) * count + snow + 1))
else:
    print((-1))

-    if i not in s: +    if not dicta[i]: