import bisect



S = eval(input())

T = eval(input())



d = [[] for _ in range(27)]

alpha2num = lambda c: ord(c) - ord("a") + 1



for i, s in enumerate(S):

    d[alpha2num(s)].append(i)



idx = -1

l = 0

ans = 0

for t in T:

    dl = d[alpha2num(t)]

    if not dl:

        ans = -1

        break

    insert_idx = bisect.bisect_right(dl, idx)

    if insert_idx == len(dl):

        l += 1

        idx = dl[0]

    else:

        idx = dl[insert_idx]

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



print(ans)
import bisect



S = eval(input())

T = eval(input())



d = [[] for _ in range(27)]

# alpha2num = lambda c: ord(c) - ord("a") + 1

d = {chr(c): [] for c in range(ord("a"), ord("z")+1)}



for i, s in enumerate(S):

    # d[alpha2num(s)].append(i)

    d[s].append(i)



idx = -1

l = 0

ans = 0

for t in T:

    # dl = d[alpha2num(t)]

    dl = d[t]

    if not dl:

        ans = -1

        break

    insert_idx = bisect.bisect_right(dl, idx)

    if insert_idx == len(dl):

        l += 1

        idx = dl[0]

    else:

        idx = dl[insert_idx]

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



print(ans)
import bisect

S = eval(input())
T = eval(input())
d = [[] for _ in range(27)]
alpha2num = lambda c: ord(c) - ord("a") + 1
for i, s in enumerate(S):
    d[alpha2num(s)].append(i)
idx = -1
l = 0
ans = 0
for t in T:
    dl = d[alpha2num(t)]
    if not dl:
        ans = -1
        break
    insert_idx = bisect.bisect_right(dl, idx)
    if insert_idx == len(dl):
        l += 1
        idx = dl[0]
    else:
        idx = dl[insert_idx]
    ans = l * len(S) + idx + 1
print(ans)

import bisect

S = eval(input())
T = eval(input())
d = [[] for _ in range(27)]
# alpha2num = lambda c: ord(c) - ord("a") + 1
d = {chr(c): [] for c in range(ord("a"), ord("z") + 1)}
for i, s in enumerate(S):
    # d[alpha2num(s)].append(i)
    d[s].append(i)
idx = -1
l = 0
ans = 0
for t in T:
    # dl = d[alpha2num(t)]
    dl = d[t]
    if not dl:
        ans = -1
        break
    insert_idx = bisect.bisect_right(dl, idx)
    if insert_idx == len(dl):
        l += 1
        idx = dl[0]
    else:
        idx = dl[insert_idx]
    ans = l * len(S) + idx + 1
print(ans)

-alpha2num = lambda c: ord(c) - ord("a") + 1 +# alpha2num = lambda c: ord(c) - ord("a") + 1 +d = {chr(c): [] for c in range(ord("a"), ord("z") + 1)} -    d[alpha2num(s)].append(i) +    # d[alpha2num(s)].append(i) +    d[s].append(i) -    dl = d[alpha2num(t)] +    # dl = d[alpha2num(t)] +    dl = d[t]