from collections import defaultdict

from bisect import bisect_right



def sol():

    S = eval(input())

    T = eval(input())



    setS = set(S)

    setT = set(T)

    for t in setT:

        if not t in setS:

            print('-1')

            return



    posS = defaultdict(list)



    for i, s in enumerate(S):

        posS[s].append(i)



    for s in enumerate(S):

        posS[s].sort()



    prev = -1

    ans = 0

    N = len(S)



    for t in T:

        next = bisect_right(posS[t], prev)

        if next >= len(posS[t]):

            ans += N - prev

            ans += posS[t][0]

            prev = posS[t][0]

        else:

            ans += posS[t][next] - prev

            prev = posS[t][next]



    print(ans)



sol()

from bisect import bisect_left



S = eval(input())

T = eval(input())



if not set(list(T)) <= set(list(S)):

    print((-1))

    exit()



sToI = {s: [] for s in set(list(S))}

for i, s in enumerate(S):

    sToI[s].append(i)



now = 0

R = 0

for t in T:

    I = sToI[t]

    nx = bisect_left(I, now)



    if nx == len(I):

        nx = 0

        R += 1



    now = I[nx] + 1



print((now + R * len(S)))

from collections import defaultdict
from bisect import bisect_right


def sol():
    S = eval(input())
    T = eval(input())
    setS = set(S)
    setT = set(T)
    for t in setT:
        if not t in setS:
            print("-1")
            return
    posS = defaultdict(list)
    for i, s in enumerate(S):
        posS[s].append(i)
    for s in enumerate(S):
        posS[s].sort()
    prev = -1
    ans = 0
    N = len(S)
    for t in T:
        next = bisect_right(posS[t], prev)
        if next >= len(posS[t]):
            ans += N - prev
            ans += posS[t][0]
            prev = posS[t][0]
        else:
            ans += posS[t][next] - prev
            prev = posS[t][next]
    print(ans)


sol()

from bisect import bisect_left

S = eval(input())
T = eval(input())
if not set(list(T)) <= set(list(S)):
    print((-1))
    exit()
sToI = {s: [] for s in set(list(S))}
for i, s in enumerate(S):
    sToI[s].append(i)
now = 0
R = 0
for t in T:
    I = sToI[t]
    nx = bisect_left(I, now)
    if nx == len(I):
        nx = 0
        R += 1
    now = I[nx] + 1
print((now + R * len(S)))

-from collections import defaultdict -from bisect import bisect_right +from bisect import bisect_left - -def sol(): -    S = eval(input()) -    T = eval(input()) -    setS = set(S) -    setT = set(T) -    for t in setT: -        if not t in setS: -            print("-1") -            return -    posS = defaultdict(list) -    for i, s in enumerate(S): -        posS[s].append(i) -    for s in enumerate(S): -        posS[s].sort() -    prev = -1 -    ans = 0 -    N = len(S) -    for t in T: -        next = bisect_right(posS[t], prev) -        if next >= len(posS[t]): -            ans += N - prev -            ans += posS[t][0] -            prev = posS[t][0] -        else: -            ans += posS[t][next] - prev -            prev = posS[t][next] -    print(ans) - - -sol() +S = eval(input()) +T = eval(input()) +if not set(list(T)) <= set(list(S)): +    print((-1)) +    exit() +sToI = {s: [] for s in set(list(S))} +for i, s in enumerate(S): +    sToI[s].append(i) +now = 0 +R = 0 +for t in T: +    I = sToI[t] +    nx = bisect_left(I, now) +    if nx == len(I): +        nx = 0 +        R += 1 +    now = I[nx] + 1 +print((now + R * len(S)))