import bisect

S = list(eval(input()))

T = list(eval(input()))

s_dict = {}

# 二週分の文字とインデックス番号の組み合わせを保持

for s in S:

    s_dict[s] = []

for i, s in enumerate(S+S):

    bisect.insort_right(s_dict[s], i)



N = len(S)

try:

    ret = 0

    cnt = 0

    pre_t_idx = -1

    for t in T:

        t_idx = s_dict[t][bisect.bisect_right(s_dict[t], pre_t_idx)]

        if t_idx > N-1:

            cnt += 1

            t_idx -= N

        ret = t_idx+1

        pre_t_idx = t_idx



    print((cnt*N+ret))

except Exception as e:

    print((-1))

from bisect import bisect_right



def main():

    S = eval(input())

    T = eval(input())

    lens = len(S)

    s = set(S)

    t = set(T)

    for i in t:

        if not i in s:

            return -2

    S = S + S

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

    for i, v in enumerate(S):

        alpha[ord(v)-ord('a')].append(i)

    ans = 0

    idx = -1

    cnt = 0

    for i in T:

        # 二分探索で探す

        idx = bisect_right(alpha[ord(i)-ord('a')], idx)

        idx = alpha[ord(i)-ord('a')][idx]

        cnt += idx // lens

        idx %= lens

        ans = cnt * lens + idx

    return ans



print((main()+1))

import bisect

S = list(eval(input()))
T = list(eval(input()))
s_dict = {}
# 二週分の文字とインデックス番号の組み合わせを保持
for s in S:
    s_dict[s] = []
for i, s in enumerate(S + S):
    bisect.insort_right(s_dict[s], i)
N = len(S)
try:
    ret = 0
    cnt = 0
    pre_t_idx = -1
    for t in T:
        t_idx = s_dict[t][bisect.bisect_right(s_dict[t], pre_t_idx)]
        if t_idx > N - 1:
            cnt += 1
            t_idx -= N
        ret = t_idx + 1
        pre_t_idx = t_idx
    print((cnt * N + ret))
except Exception as e:
    print((-1))

from bisect import bisect_right


def main():
    S = eval(input())
    T = eval(input())
    lens = len(S)
    s = set(S)
    t = set(T)
    for i in t:
        if not i in s:
            return -2
    S = S + S
    alpha = [[] for i in range(26)]
    for i, v in enumerate(S):
        alpha[ord(v) - ord("a")].append(i)
    ans = 0
    idx = -1
    cnt = 0
    for i in T:
        # 二分探索で探す
        idx = bisect_right(alpha[ord(i) - ord("a")], idx)
        idx = alpha[ord(i) - ord("a")][idx]
        cnt += idx // lens
        idx %= lens
        ans = cnt * lens + idx
    return ans


print((main() + 1))

-import bisect +from bisect import bisect_right -S = list(eval(input())) -T = list(eval(input())) -s_dict = {} -# 二週分の文字とインデックス番号の組み合わせを保持 -for s in S: -    s_dict[s] = [] -for i, s in enumerate(S + S): -    bisect.insort_right(s_dict[s], i) -N = len(S) -try: -    ret = 0 + +def main(): +    S = eval(input()) +    T = eval(input()) +    lens = len(S) +    s = set(S) +    t = set(T) +    for i in t: +        if not i in s: +            return -2 +    S = S + S +    alpha = [[] for i in range(26)] +    for i, v in enumerate(S): +        alpha[ord(v) - ord("a")].append(i) +    ans = 0 +    idx = -1 -    pre_t_idx = -1 -    for t in T: -        t_idx = s_dict[t][bisect.bisect_right(s_dict[t], pre_t_idx)] -        if t_idx > N - 1: -            cnt += 1 -            t_idx -= N -        ret = t_idx + 1 -        pre_t_idx = t_idx -    print((cnt * N + ret)) -except Exception as e: -    print((-1)) +    for i in T: +        # 二分探索で探す +        idx = bisect_right(alpha[ord(i) - ord("a")], idx) +        idx = alpha[ord(i) - ord("a")][idx] +        cnt += idx // lens +        idx %= lens +        ans = cnt * lens + idx +    return ans + + +print((main() + 1))