import sys

import bisect

def main():

    input = sys.stdin.readline

    s = input().rstrip()

    t = input().rstrip()



    letters = set(t)

    indices = dict()

    for l in letters:

        lst = []

        left = 0

        while left < len(s):

            i = s.find(l, left)

            if i < 0: break

            lst.append(i)

            left = i+1

        if not lst:

            print((-1))

            exit()

        indices[l] = lst

    

    offset = 0

    cycle = 0

    for l in t:

        ind = indices[l]

        i = bisect.bisect_left(ind, offset)

        if i < len(ind):

            offset = ind[i] + 1

        else:

            offset = ind[0] + 1

            cycle += 1

        if offset >= len(s):

            offset %= len(s)

            cycle += 1



    print((len(s)*cycle + offset))



if __name__ == '__main__':

    main()
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)

from bisect import bisect_left

from collections import defaultdict

import sys

def main(S, T):

    D = defaultdict(list)

    for i, s in enumerate(S):

        D[s].append(i + 1)

    cycle = 0

    idx = 0

    N = len(S)

    for t in T:

        if not D[t]:

            return -1

        i = bisect_left(D[t], idx + 1)

        if i >= len(D[t]):

            cycle += 1

            idx = D[t][0]

        else:

            idx = D[t][i]

    return cycle * N + idx



if __name__ == '__main__':

    input = sys.stdin.readline

    s = input().rstrip()

    t = input().rstrip()

    ans = main(s, t)

    print(ans)

import sys
import bisect


def main():
    input = sys.stdin.readline
    s = input().rstrip()
    t = input().rstrip()
    letters = set(t)
    indices = dict()
    for l in letters:
        lst = []
        left = 0
        while left < len(s):
            i = s.find(l, left)
            if i < 0:
                break
            lst.append(i)
            left = i + 1
        if not lst:
            print((-1))
            exit()
        indices[l] = lst
    offset = 0
    cycle = 0
    for l in t:
        ind = indices[l]
        i = bisect.bisect_left(ind, offset)
        if i < len(ind):
            offset = ind[i] + 1
        else:
            offset = ind[0] + 1
            cycle += 1
        if offset >= len(s):
            offset %= len(s)
            cycle += 1
    print((len(s) * cycle + offset))


if __name__ == "__main__":
    main()

# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
from bisect import bisect_left
from collections import defaultdict
import sys


def main(S, T):
    D = defaultdict(list)
    for i, s in enumerate(S):
        D[s].append(i + 1)
    cycle = 0
    idx = 0
    N = len(S)
    for t in T:
        if not D[t]:
            return -1
        i = bisect_left(D[t], idx + 1)
        if i >= len(D[t]):
            cycle += 1
            idx = D[t][0]
        else:
            idx = D[t][i]
    return cycle * N + idx


if __name__ == "__main__":
    input = sys.stdin.readline
    s = input().rstrip()
    t = input().rstrip()
    ans = main(s, t)
    print(ans)

+# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..) +from bisect import bisect_left +from collections import defaultdict -import bisect -def main(): +def main(S, T): +    D = defaultdict(list) +    for i, s in enumerate(S): +        D[s].append(i + 1) +    cycle = 0 +    idx = 0 +    N = len(S) +    for t in T: +        if not D[t]: +            return -1 +        i = bisect_left(D[t], idx + 1) +        if i >= len(D[t]): +            cycle += 1 +            idx = D[t][0] +        else: +            idx = D[t][i] +    return cycle * N + idx + + +if __name__ == "__main__": -    letters = set(t) -    indices = dict() -    for l in letters: -        lst = [] -        left = 0 -        while left < len(s): -            i = s.find(l, left) -            if i < 0: -                break -            lst.append(i) -            left = i + 1 -        if not lst: -            print((-1)) -            exit() -        indices[l] = lst -    offset = 0 -    cycle = 0 -    for l in t: -        ind = indices[l] -        i = bisect.bisect_left(ind, offset) -        if i < len(ind): -            offset = ind[i] + 1 -        else: -            offset = ind[0] + 1 -            cycle += 1 -        if offset >= len(s): -            offset %= len(s) -            cycle += 1 -    print((len(s) * cycle + offset)) - - -if __name__ == "__main__": -    main() +    ans = main(s, t) +    print(ans)