import sys

input=sys.stdin.readline

import string

import bisect



def main():



    S = input().strip()

    T = input().strip()

    if any(S.find(c) < 0 for c in T):

        print((-1))

        return



    dS = {c:[] for c in string.ascii_lowercase}

    for i, s in enumerate(S):

        dS[s].append(i)

    

    ans = 0

    pos = 0

    ls = len(S)

    for c in T:

        if dS[c][-1] < pos:

            pos = 0

            ans += ls

        bi = bisect.bisect_left(dS[c], pos)

        pos = dS[c][bi] + 1



    print((ans + pos))



if __name__ == '__main__':

    main()

import sys

input=sys.stdin.readline

import string

import bisect



def main():



    S = input().strip()

    T = input().strip()



    dS = {c:[] for c in string.ascii_lowercase}

    for i, s in enumerate(S):

        dS[s].append(i)

    

    ans = 0

    pos = 0

    ls = len(S)

    for c in T:

        if not dS[c]:

            print((-1))

            return

        if dS[c][-1] < pos:

            pos = 0

            ans += ls

        bi = bisect.bisect_left(dS[c], pos)

        pos = dS[c][bi] + 1



    print((ans + pos))



if __name__ == '__main__':

    main()

import sys

input = sys.stdin.readline
import string
import bisect


def main():
    S = input().strip()
    T = input().strip()
    if any(S.find(c) < 0 for c in T):
        print((-1))
        return
    dS = {c: [] for c in string.ascii_lowercase}
    for i, s in enumerate(S):
        dS[s].append(i)
    ans = 0
    pos = 0
    ls = len(S)
    for c in T:
        if dS[c][-1] < pos:
            pos = 0
            ans += ls
        bi = bisect.bisect_left(dS[c], pos)
        pos = dS[c][bi] + 1
    print((ans + pos))


if __name__ == "__main__":
    main()

import sys

input = sys.stdin.readline
import string
import bisect


def main():
    S = input().strip()
    T = input().strip()
    dS = {c: [] for c in string.ascii_lowercase}
    for i, s in enumerate(S):
        dS[s].append(i)
    ans = 0
    pos = 0
    ls = len(S)
    for c in T:
        if not dS[c]:
            print((-1))
            return
        if dS[c][-1] < pos:
            pos = 0
            ans += ls
        bi = bisect.bisect_left(dS[c], pos)
        pos = dS[c][bi] + 1
    print((ans + pos))


if __name__ == "__main__":
    main()

-    if any(S.find(c) < 0 for c in T): -        print((-1)) -        return +        if not dS[c]: +            print((-1)) +            return