s = eval(input())

t = eval(input())

lent = len(t)

tcount = 0

snow = 0

count = 0

flag = True

if t[0] not in s:

    print((-1))

else:

    snow = s.index(t[0])

    while True:

        tcount += 1

        if tcount == lent:

            break

        if t[tcount] in s[snow+1:]:

            snow = s[snow+1:].index(t[tcount])+snow+1

        elif t[tcount] in s:

            snow = s.index(t[tcount])

            count += 1

        else:

            flag = False

            break

    if flag:

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

    else:

        print((-1))
from collections import defaultdict

import bisect

s = eval(input())

t = eval(input())

dicta = defaultdict(list)

for i in range(len(s)):

    dicta[s[i]] += [i]

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))

        
s = eval(input())
t = eval(input())
lent = len(t)
tcount = 0
snow = 0
count = 0
flag = True
if t[0] not in s:
    print((-1))
else:
    snow = s.index(t[0])
    while True:
        tcount += 1
        if tcount == lent:
            break
        if t[tcount] in s[snow + 1 :]:
            snow = s[snow + 1 :].index(t[tcount]) + snow + 1
        elif t[tcount] in s:
            snow = s.index(t[tcount])
            count += 1
        else:
            flag = False
            break
    if flag:
        print((count * len(s) + snow + 1))
    else:
        print((-1))

from collections import defaultdict
import bisect

s = eval(input())
t = eval(input())
dicta = defaultdict(list)
for i in range(len(s)):
    dicta[s[i]] += [i]
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 + -lent = len(t) -tcount = 0 -snow = 0 +dicta = defaultdict(list) +for i in range(len(s)): +    dicta[s[i]] += [i] +snow = -1 -if t[0] not in s: +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: -else: -    snow = s.index(t[0]) -    while True: -        tcount += 1 -        if tcount == lent: -            break -        if t[tcount] in s[snow + 1 :]: -            snow = s[snow + 1 :].index(t[tcount]) + snow + 1 -        elif t[tcount] in s: -            snow = s.index(t[tcount]) -            count += 1 -        else: -            flag = False -            break -    if flag: -        print((count * len(s) + snow + 1)) -    else: -        print((-1))