def next(str):

    N = len(str)

    nxt = [[N] * 26 for i in range(N + 1)]

    for i in range(N - 1, -1, -1):

        for j in range(26):

            nxt[i][j] = nxt[i + 1][j]

        nxt[i][ord(str[i]) - ord('a')] = i

    return nxt



def solve():

    S = eval(input())

    T = eval(input())

    N = len(S)

    M = 2 * N

    S += S

    nxt = next(S)

    ans = -1

    for c in T:

        i = ans % N

        pos = ord(c) - ord('a')

        if nxt[i + 1][pos] == M:

            return -1

        ans += nxt[i + 1][pos] - i

    return ans + 1



print((solve()))

from bisect import bisect



def ctoi(c):

    return ord(c) - ord('a')



def solve():

    S = eval(input())

    T = eval(input())

    N = len(S)

    idx = [[] for i in range(26)]

    for i in range(2 * N):

        idx[ctoi(S[i % N])].append(i)

    ans = -1

    for c in T:

        if not idx[ctoi(c)]:

            return -1

        ans += idx[ctoi(c)][bisect(idx[ctoi(c)], ans % N)] - ans % N

    return ans + 1

print((solve()))

def next(str):
    N = len(str)
    nxt = [[N] * 26 for i in range(N + 1)]
    for i in range(N - 1, -1, -1):
        for j in range(26):
            nxt[i][j] = nxt[i + 1][j]
        nxt[i][ord(str[i]) - ord("a")] = i
    return nxt


def solve():
    S = eval(input())
    T = eval(input())
    N = len(S)
    M = 2 * N
    S += S
    nxt = next(S)
    ans = -1
    for c in T:
        i = ans % N
        pos = ord(c) - ord("a")
        if nxt[i + 1][pos] == M:
            return -1
        ans += nxt[i + 1][pos] - i
    return ans + 1


print((solve()))

from bisect import bisect


def ctoi(c):
    return ord(c) - ord("a")


def solve():
    S = eval(input())
    T = eval(input())
    N = len(S)
    idx = [[] for i in range(26)]
    for i in range(2 * N):
        idx[ctoi(S[i % N])].append(i)
    ans = -1
    for c in T:
        if not idx[ctoi(c)]:
            return -1
        ans += idx[ctoi(c)][bisect(idx[ctoi(c)], ans % N)] - ans % N
    return ans + 1


print((solve()))

-def next(str): -    N = len(str) -    nxt = [[N] * 26 for i in range(N + 1)] -    for i in range(N - 1, -1, -1): -        for j in range(26): -            nxt[i][j] = nxt[i + 1][j] -        nxt[i][ord(str[i]) - ord("a")] = i -    return nxt +from bisect import bisect + + +def ctoi(c): +    return ord(c) - ord("a") -    M = 2 * N -    S += S -    nxt = next(S) +    idx = [[] for i in range(26)] +    for i in range(2 * N): +        idx[ctoi(S[i % N])].append(i) -        i = ans % N -        pos = ord(c) - ord("a") -        if nxt[i + 1][pos] == M: +        if not idx[ctoi(c)]: -        ans += nxt[i + 1][pos] - i +        ans += idx[ctoi(c)][bisect(idx[ctoi(c)], ans % N)] - ans % N