# ABC138E - Strings of Impurity

def main():

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

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

        print((-1))

        return

    ans, cur, idx, lim = 1, 0, -1, len(T)

    while cur < lim:

        find = S[idx + 1:].find(T[cur])

        if find == -1:

            ans += 1

            idx = -1

        else:

            idx += find + 1

            cur += 1

    ans = (ans - 1) * len(S) + idx + 1

    print(ans)





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
def main():
    S, T = tuple(eval(input()) for _ in range(2))
    if not set(T) <= set(S):  # corner case
        print((-1))
        return
    ans, cur, idx, lim = 1, 0, -1, len(T)
    while cur < lim:
        find = S[idx + 1 :].find(T[cur])
        if find == -1:
            ans += 1
            idx = -1
        else:
            idx += find + 1
            cur += 1
    ans = (ans - 1) * len(S) + idx + 1
    print(ans)


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()

+from bisect import bisect_left as bs +from collections import defaultdict + + -    ans, cur, idx, lim = 1, 0, -1, len(T) -    while cur < lim: -        find = S[idx + 1 :].find(T[cur]) -        if find == -1: -            ans += 1 -            idx = -1 +    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 -            idx += find + 1 -            cur += 1 -    ans = (ans - 1) * len(S) + idx + 1 -    print(ans) +            cur += 1 + tgt[0] - x + ls +    print((cur + 1))