from bisect import bisect_left

import sys



input = sys.stdin.readline



s = input().strip()

n = len(s)

t = input().strip()



d = [[] for _ in range(26)]

base = ord('a')

for i, c in enumerate(s):

    idx = ord(c) - base

    d[idx].append(i)



string_count = 0

cur = -1

for tt in t:

    cur += 1

    idx = ord(tt) - base

    pos_lst = d[idx]

    lst_len = len(pos_lst)



    if not lst_len:

        print((-1))

        exit()

    pos = bisect_left(pos_lst, cur)  # cur以降で文字ttが見つかる位置

    if lst_len == pos:

        string_count += 1

        cur = pos_lst[0]

    else:

        cur = pos_lst[pos]



    # print(cur, pos_lst, lst_len, string_count * n)



print((string_count * n + cur + 1))

def main():

    from bisect import bisect_left



    S = eval(input())

    T = eval(input())



    L = len(S)



    pos = tuple(list() for _ in range(26))

    orda = ord('a')

    for i, c in enumerate(S):

        j = ord(c) - orda

        pos[j].append(i)



    rep = 0

    curr = 0

    for c in T:

        j = ord(c) - orda



        if not pos[j]:

            print((-1))

            return



        i = bisect_left(pos[j], curr)

        if i == len(pos[j]):

            rep += 1

            i = 0  # pos[j][0]文字目がc

        curr = pos[j][i] + 1  # pos[j][i]にしたら同じ文字が続くケースでWA



    print((rep * L + curr))





if __name__ == '__main__':

    main()

from bisect import bisect_left
import sys

input = sys.stdin.readline
s = input().strip()
n = len(s)
t = input().strip()
d = [[] for _ in range(26)]
base = ord("a")
for i, c in enumerate(s):
    idx = ord(c) - base
    d[idx].append(i)
string_count = 0
cur = -1
for tt in t:
    cur += 1
    idx = ord(tt) - base
    pos_lst = d[idx]
    lst_len = len(pos_lst)
    if not lst_len:
        print((-1))
        exit()
    pos = bisect_left(pos_lst, cur)  # cur以降で文字ttが見つかる位置
    if lst_len == pos:
        string_count += 1
        cur = pos_lst[0]
    else:
        cur = pos_lst[pos]
    # print(cur, pos_lst, lst_len, string_count * n)
print((string_count * n + cur + 1))

def main():
    from bisect import bisect_left

    S = eval(input())
    T = eval(input())
    L = len(S)
    pos = tuple(list() for _ in range(26))
    orda = ord("a")
    for i, c in enumerate(S):
        j = ord(c) - orda
        pos[j].append(i)
    rep = 0
    curr = 0
    for c in T:
        j = ord(c) - orda
        if not pos[j]:
            print((-1))
            return
        i = bisect_left(pos[j], curr)
        if i == len(pos[j]):
            rep += 1
            i = 0  # pos[j][0]文字目がc
        curr = pos[j][i] + 1  # pos[j][i]にしたら同じ文字が続くケースでWA
    print((rep * L + curr))


if __name__ == "__main__":
    main()

-from bisect import bisect_left -import sys +def main(): +    from bisect import bisect_left -input = sys.stdin.readline -s = input().strip() -n = len(s) -t = input().strip() -d = [[] for _ in range(26)] -base = ord("a") -for i, c in enumerate(s): -    idx = ord(c) - base -    d[idx].append(i) -string_count = 0 -cur = -1 -for tt in t: -    cur += 1 -    idx = ord(tt) - base -    pos_lst = d[idx] -    lst_len = len(pos_lst) -    if not lst_len: -        print((-1)) -        exit() -    pos = bisect_left(pos_lst, cur)  # cur以降で文字ttが見つかる位置 -    if lst_len == pos: -        string_count += 1 -        cur = pos_lst[0] -    else: -        cur = pos_lst[pos] -    # print(cur, pos_lst, lst_len, string_count * n) -print((string_count * n + cur + 1)) +    S = eval(input()) +    T = eval(input()) +    L = len(S) +    pos = tuple(list() for _ in range(26)) +    orda = ord("a") +    for i, c in enumerate(S): +        j = ord(c) - orda +        pos[j].append(i) +    rep = 0 +    curr = 0 +    for c in T: +        j = ord(c) - orda +        if not pos[j]: +            print((-1)) +            return +        i = bisect_left(pos[j], curr) +        if i == len(pos[j]): +            rep += 1 +            i = 0  # pos[j][0]文字目がc +        curr = pos[j][i] + 1  # pos[j][i]にしたら同じ文字が続くケースでWA +    print((rep * L + curr)) + + +if __name__ == "__main__": +    main()