from collections import defaultdict

from bisect import bisect_right



def main():

    S = eval(input())

    T = eval(input())

    d = defaultdict(list)

    for i, s in enumerate(S):

        d[s].append(i+1)

    pre = 0

    cnt = 0

    loop = 0

    len_S = len(S)

    for t in T:

        if not d[t]:

            print((-1))

            exit()

        index = bisect_right(d[t],pre)

        if index > len(d[t])-1:

            pre = 0

            loop += 1

            index = bisect_right(d[t],pre)

        pre = d[t][index]

        

    ans = loop * len_S + pre

    print(ans)













if __name__ == "__main__":

    main()
from collections import defaultdict

from bisect import bisect_right



def main():

    S = eval(input())

    T = eval(input())

    Ls = len(S)

    Lt = len(T)

    d = defaultdict(list)

    for i in range(Ls):

        d[S[i]].append(i+1)



    now = 0

    ans = 0

    for i in range(Lt):

        if not d[T[i]]:

            print((-1))

            exit()

        ni = bisect_right(d[T[i]], now)

        if ni >= len(d[T[i]]):

            now = 0

            ans += Ls

            ni = bisect_right(d[T[i]], now)

            now = d[T[i]][ni]

        else:

            now = d[T[i]][ni]



    ans += now

    print(ans)





if __name__ == "__main__":

    main()
from collections import defaultdict
from bisect import bisect_right


def main():
    S = eval(input())
    T = eval(input())
    d = defaultdict(list)
    for i, s in enumerate(S):
        d[s].append(i + 1)
    pre = 0
    cnt = 0
    loop = 0
    len_S = len(S)
    for t in T:
        if not d[t]:
            print((-1))
            exit()
        index = bisect_right(d[t], pre)
        if index > len(d[t]) - 1:
            pre = 0
            loop += 1
            index = bisect_right(d[t], pre)
        pre = d[t][index]
    ans = loop * len_S + pre
    print(ans)


if __name__ == "__main__":
    main()

from collections import defaultdict
from bisect import bisect_right


def main():
    S = eval(input())
    T = eval(input())
    Ls = len(S)
    Lt = len(T)
    d = defaultdict(list)
    for i in range(Ls):
        d[S[i]].append(i + 1)
    now = 0
    ans = 0
    for i in range(Lt):
        if not d[T[i]]:
            print((-1))
            exit()
        ni = bisect_right(d[T[i]], now)
        if ni >= len(d[T[i]]):
            now = 0
            ans += Ls
            ni = bisect_right(d[T[i]], now)
            now = d[T[i]][ni]
        else:
            now = d[T[i]][ni]
    ans += now
    print(ans)


if __name__ == "__main__":
    main()

+    Ls = len(S) +    Lt = len(T) -    for i, s in enumerate(S): -        d[s].append(i + 1) -    pre = 0 -    cnt = 0 -    loop = 0 -    len_S = len(S) -    for t in T: -        if not d[t]: +    for i in range(Ls): +        d[S[i]].append(i + 1) +    now = 0 +    ans = 0 +    for i in range(Lt): +        if not d[T[i]]: -        index = bisect_right(d[t], pre) -        if index > len(d[t]) - 1: -            pre = 0 -            loop += 1 -            index = bisect_right(d[t], pre) -        pre = d[t][index] -    ans = loop * len_S + pre +        ni = bisect_right(d[T[i]], now) +        if ni >= len(d[T[i]]): +            now = 0 +            ans += Ls +            ni = bisect_right(d[T[i]], now) +            now = d[T[i]][ni] +        else: +            now = d[T[i]][ni] +    ans += now