# ABC138E - Strings of Impurity

from bisect import bisect_left as bs

from collections import defaultdict





def main():

    S, T = tuple(eval(input()) for _ in range(2))

    if not set(T) <= set(S):  # corner case

        print((-1))

        return

    idx, ls = defaultdict(list), len(S)

    for i, s in enumerate(S):

        idx[s] += [i]

    cur = -1

    for t in T:

        tgt = idx[t]

        x = (cur + 1) % ls

        i = bs(tgt, x)

        if i < len(tgt):

            cur += 1 + tgt[i] - x

        else:

            cur += 1 + tgt[0] - x + ls

    print((cur + 1))





if __name__ == "__main__":

    main()
# ABC138E - Strings of Impurity

from bisect import bisect_left as bs

from collections import defaultdict





def main():

    S, T = tuple(eval(input()) for _ in range(2))

    idx, ls = defaultdict(list), len(S)

    for i, s in enumerate(S):

        idx[s] += [i]

    roop, cur = 0, -1

    for t in T:

        tgt = idx[t]

        if tgt == []:  # t not in S

            print((-1))

            return

        x = bs(tgt, cur + 1)

        if x < len(tgt):

            cur = tgt[x]

        else:

            cur = tgt[0]

            roop += 1

    print((roop * ls + cur + 1))





if __name__ == "__main__":

    main()
# ABC138E - Strings of Impurity
from bisect import bisect_left as bs
from collections import defaultdict


def main():
    S, T = tuple(eval(input()) for _ in range(2))
    if not set(T) <= set(S):  # corner case
        print((-1))
        return
    idx, ls = defaultdict(list), len(S)
    for i, s in enumerate(S):
        idx[s] += [i]
    cur = -1
    for t in T:
        tgt = idx[t]
        x = (cur + 1) % ls
        i = bs(tgt, x)
        if i < len(tgt):
            cur += 1 + tgt[i] - x
        else:
            cur += 1 + tgt[0] - x + ls
    print((cur + 1))


if __name__ == "__main__":
    main()

# ABC138E - Strings of Impurity
from bisect import bisect_left as bs
from collections import defaultdict


def main():
    S, T = tuple(eval(input()) for _ in range(2))
    idx, ls = defaultdict(list), len(S)
    for i, s in enumerate(S):
        idx[s] += [i]
    roop, cur = 0, -1
    for t in T:
        tgt = idx[t]
        if tgt == []:  # t not in S
            print((-1))
            return
        x = bs(tgt, cur + 1)
        if x < len(tgt):
            cur = tgt[x]
        else:
            cur = tgt[0]
            roop += 1
    print((roop * ls + cur + 1))


if __name__ == "__main__":
    main()

-    if not set(T) <= set(S):  # corner case -        print((-1)) -        return -    cur = -1 +    roop, cur = 0, -1 -        x = (cur + 1) % ls -        i = bs(tgt, x) -        if i < len(tgt): -            cur += 1 + tgt[i] - x +        if tgt == []:  # t not in S +            print((-1)) +            return +        x = bs(tgt, cur + 1) +        if x < len(tgt): +            cur = tgt[x] -            cur += 1 + tgt[0] - x + ls -    print((cur + 1)) +            cur = tgt[0] +            roop += 1 +    print((roop * ls + cur + 1))