def slove():

    import sys

    import collections

    import bisect

    input = sys.stdin.readline

    s = str(input().rstrip('\n'))

    t = str(input().rstrip('\n'))

    d = collections.defaultdict(list)

    for i in range(len(s)):

        d[s[i]] += [i]



    loop = 0

    pos = 0

    for i in range(len(t)):

        if t[i] not in d:

            print((-1))

            exit()

        else:

            pos = bisect.bisect_left(d[t[i]], pos)

            if len(d[t[i]]) == pos:

                loop += 1

                pos = 0

            pos = d[t[i]][pos] + 1

    print((loop * len(s) + pos))





if __name__ == '__main__':

    slove()

import sys

import bisect

import collections





def solve():

    readline = sys.stdin.buffer.readline

    mod = 10 ** 9 + 7

    s = str(readline().rstrip().decode('utf-8'))

    d = collections.defaultdict(list)

    for i in range(len(s)):

        d[s[i]] += [i]

    loop = 0

    pos = 0

    t = str(readline().rstrip().decode('utf-8'))

    for i in range(len(t)):

        if t[i] in d:

            pos = bisect.bisect_left(d[t[i]], pos)

            if pos == len(d[t[i]]):

                loop += 1

                pos = 0

                pos = bisect.bisect_left(d[t[i]], pos)

            pos = d[t[i]][pos] + 1

        else:

            print((-1))

            exit()

    print((loop * len(s) + pos))





if __name__ == '__main__':

    solve()

def slove():
    import sys
    import collections
    import bisect

    input = sys.stdin.readline
    s = str(input().rstrip("\n"))
    t = str(input().rstrip("\n"))
    d = collections.defaultdict(list)
    for i in range(len(s)):
        d[s[i]] += [i]
    loop = 0
    pos = 0
    for i in range(len(t)):
        if t[i] not in d:
            print((-1))
            exit()
        else:
            pos = bisect.bisect_left(d[t[i]], pos)
            if len(d[t[i]]) == pos:
                loop += 1
                pos = 0
            pos = d[t[i]][pos] + 1
    print((loop * len(s) + pos))


if __name__ == "__main__":
    slove()

import sys
import bisect
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10**9 + 7
    s = str(readline().rstrip().decode("utf-8"))
    d = collections.defaultdict(list)
    for i in range(len(s)):
        d[s[i]] += [i]
    loop = 0
    pos = 0
    t = str(readline().rstrip().decode("utf-8"))
    for i in range(len(t)):
        if t[i] in d:
            pos = bisect.bisect_left(d[t[i]], pos)
            if pos == len(d[t[i]]):
                loop += 1
                pos = 0
                pos = bisect.bisect_left(d[t[i]], pos)
            pos = d[t[i]][pos] + 1
        else:
            print((-1))
            exit()
    print((loop * len(s) + pos))


if __name__ == "__main__":
    solve()

-def slove(): -    import sys -    import collections -    import bisect +import sys +import bisect +import collections -    input = sys.stdin.readline -    s = str(input().rstrip("\n")) -    t = str(input().rstrip("\n")) + +def solve(): +    readline = sys.stdin.buffer.readline +    mod = 10**9 + 7 +    s = str(readline().rstrip().decode("utf-8")) +    t = str(readline().rstrip().decode("utf-8")) -        if t[i] not in d: +        if t[i] in d: +            pos = bisect.bisect_left(d[t[i]], pos) +            if pos == len(d[t[i]]): +                loop += 1 +                pos = 0 +                pos = bisect.bisect_left(d[t[i]], pos) +            pos = d[t[i]][pos] + 1 +        else: -        else: -            pos = bisect.bisect_left(d[t[i]], pos) -            if len(d[t[i]]) == pos: -                loop += 1 -                pos = 0 -            pos = d[t[i]][pos] + 1 -    slove() +    solve()