import copy





def main():

    s = eval(input())

    ss = s + s

    t = eval(input())

    if not set(sorted(t)) <= set(sorted(s)):

        print((-1))

        return

    cnt_s = {}

    cnt_t = {}

    pos = {}  # [({}) for x in range(len(s))]

    for i in range(len(ss)):

        c = ss[i]

        if c not in cnt_s:

            cnt_s[c] = 0

            pos[c] = []

        cnt_s[c] += 1

        pos[c].append(i)

    # for k in pos.keys():

    #     pos[k].reverse()

    # org_pos = copy.deepcopy(pos)

    ret = 0

    tmp = -1

    for i in range(len(t)):

        c = t[i]

        if pos[c][0] > tmp:

            tmp = pos[c][0]

            continue

        l = 1

        r = len(pos[c]) - 1

        while not l == r:

            p = (l + r) // 2

            if pos[c][p] > tmp:

                r = p

            if pos[c][p] <= tmp:

                l = p + 1

        tmp = pos[c][l]

        if tmp >= len(s):

            ret += len(s)

            tmp -= len(s)

    ret += tmp + 1

    print(ret)

    return





if __name__ == "__main__":

    main()

from bisect import bisect





def main():

    S = eval(input())

    T = eval(input())



    pos = {}

    for i, c in enumerate(S):

        if c not in list(pos.keys()):

            pos[c] = []

        pos[c].append(i)



    ret = 0

    tmp = -1

    for c in T:

        if c not in list(pos.keys()):

            print((-1))

            return

        idx = bisect(pos[c], tmp)

        if idx == len(pos[c]):

            ret += len(S)

            tmp = pos[c][0]

        else:

            tmp = pos[c][idx]



    ret += tmp + 1

    print(ret)

    return





if __name__ == "__main__":

    main()

import copy


def main():
    s = eval(input())
    ss = s + s
    t = eval(input())
    if not set(sorted(t)) <= set(sorted(s)):
        print((-1))
        return
    cnt_s = {}
    cnt_t = {}
    pos = {}  # [({}) for x in range(len(s))]
    for i in range(len(ss)):
        c = ss[i]
        if c not in cnt_s:
            cnt_s[c] = 0
            pos[c] = []
        cnt_s[c] += 1
        pos[c].append(i)
    # for k in pos.keys():
    #     pos[k].reverse()
    # org_pos = copy.deepcopy(pos)
    ret = 0
    tmp = -1
    for i in range(len(t)):
        c = t[i]
        if pos[c][0] > tmp:
            tmp = pos[c][0]
            continue
        l = 1
        r = len(pos[c]) - 1
        while not l == r:
            p = (l + r) // 2
            if pos[c][p] > tmp:
                r = p
            if pos[c][p] <= tmp:
                l = p + 1
        tmp = pos[c][l]
        if tmp >= len(s):
            ret += len(s)
            tmp -= len(s)
    ret += tmp + 1
    print(ret)
    return


if __name__ == "__main__":
    main()

from bisect import bisect


def main():
    S = eval(input())
    T = eval(input())
    pos = {}
    for i, c in enumerate(S):
        if c not in list(pos.keys()):
            pos[c] = []
        pos[c].append(i)
    ret = 0
    tmp = -1
    for c in T:
        if c not in list(pos.keys()):
            print((-1))
            return
        idx = bisect(pos[c], tmp)
        if idx == len(pos[c]):
            ret += len(S)
            tmp = pos[c][0]
        else:
            tmp = pos[c][idx]
    ret += tmp + 1
    print(ret)
    return


if __name__ == "__main__":
    main()

-import copy +from bisect import bisect -    s = eval(input()) -    ss = s + s -    t = eval(input()) -    if not set(sorted(t)) <= set(sorted(s)): -        print((-1)) -        return -    cnt_s = {} -    cnt_t = {} -    pos = {}  # [({}) for x in range(len(s))] -    for i in range(len(ss)): -        c = ss[i] -        if c not in cnt_s: -            cnt_s[c] = 0 +    S = eval(input()) +    T = eval(input()) +    pos = {} +    for i, c in enumerate(S): +        if c not in list(pos.keys()): -        cnt_s[c] += 1 -    # for k in pos.keys(): -    #     pos[k].reverse() -    # org_pos = copy.deepcopy(pos) -    for i in range(len(t)): -        c = t[i] -        if pos[c][0] > tmp: +    for c in T: +        if c not in list(pos.keys()): +            print((-1)) +            return +        idx = bisect(pos[c], tmp) +        if idx == len(pos[c]): +            ret += len(S) -            continue -        l = 1 -        r = len(pos[c]) - 1 -        while not l == r: -            p = (l + r) // 2 -            if pos[c][p] > tmp: -                r = p -            if pos[c][p] <= tmp: -                l = p + 1 -        tmp = pos[c][l] -        if tmp >= len(s): -            ret += len(s) -            tmp -= len(s) +        else: +            tmp = pos[c][idx]