from collections import defaultdict

from bisect import bisect_left



s = eval(input())

t = eval(input())



if set(s) >= set(t):

    d = defaultdict(list)

    for i, x in enumerate(s * 2):

        d[x].append(i)

    

    ans = 0

    cur = 0

    N = len(s)

    for x in t:

        cur_new = d[x][bisect_left(d[x], cur)]

        ans += cur_new - cur + 1

        cur = (cur_new + 1) % N



    print(ans)

else:

    print((-1))

from collections import defaultdict

from bisect import bisect_right



s = eval(input())

t = eval(input())



indices = defaultdict(list)

for i, v in enumerate(s):

    indices[v].append(i)



cnt = 0

cur = -1

mod = len(s)

flag = False

for v in t:

    if v not in indices:

        flag = True

        break



    i = bisect_right(indices[v], cur)

    if i == len(indices[v]):

        j = indices[v][0]

    else:

        j = indices[v][i]



    if cur >= j:

        cnt += 1

    cur = j



if flag:

    print((-1))

else:

    print((cnt * mod + cur + 1))

from collections import defaultdict
from bisect import bisect_left

s = eval(input())
t = eval(input())
if set(s) >= set(t):
    d = defaultdict(list)
    for i, x in enumerate(s * 2):
        d[x].append(i)
    ans = 0
    cur = 0
    N = len(s)
    for x in t:
        cur_new = d[x][bisect_left(d[x], cur)]
        ans += cur_new - cur + 1
        cur = (cur_new + 1) % N
    print(ans)
else:
    print((-1))

from collections import defaultdict
from bisect import bisect_right

s = eval(input())
t = eval(input())
indices = defaultdict(list)
for i, v in enumerate(s):
    indices[v].append(i)
cnt = 0
cur = -1
mod = len(s)
flag = False
for v in t:
    if v not in indices:
        flag = True
        break
    i = bisect_right(indices[v], cur)
    if i == len(indices[v]):
        j = indices[v][0]
    else:
        j = indices[v][i]
    if cur >= j:
        cnt += 1
    cur = j
if flag:
    print((-1))
else:
    print((cnt * mod + cur + 1))

-from bisect import bisect_left +from bisect import bisect_right -if set(s) >= set(t): -    d = defaultdict(list) -    for i, x in enumerate(s * 2): -        d[x].append(i) -    ans = 0 -    cur = 0 -    N = len(s) -    for x in t: -        cur_new = d[x][bisect_left(d[x], cur)] -        ans += cur_new - cur + 1 -        cur = (cur_new + 1) % N -    print(ans) +indices = defaultdict(list) +for i, v in enumerate(s): +    indices[v].append(i) +cnt = 0 +cur = -1 +mod = len(s) +flag = False +for v in t: +    if v not in indices: +        flag = True +        break +    i = bisect_right(indices[v], cur) +    if i == len(indices[v]): +        j = indices[v][0] +    else: +        j = indices[v][i] +    if cur >= j: +        cnt += 1 +    cur = j +if flag: +    print((-1)) -    print((-1)) +    print((cnt * mod + cur + 1))