import sys

input = sys.stdin.readline

sys.setrecursionlimit(10 ** 7)



from collections import defaultdict

from bisect import bisect_left



S = input().rstrip()

T = input().rstrip()



LS = len(S)



index = defaultdict(list) # alphabet to indices



for i,s in enumerate(S):

    index[s].append(i)



index



x = -1 # 今見た場所。次はx+1以上からとる。

for t in T:

    arr = index[t]

    if len(arr) == 0:

        x = -2

        break

    y = (x+1)%LS

    i = bisect_left(arr,y)

    if i < len(arr):

        next_x = (x+1) + arr[i] - y

    else:

        next_x = (x+1) + arr[0] - y + LS

    x = next_x



answer = x+1

print(answer)
import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



from bisect import bisect_right



S = [ord(x)-ord('a') for x in readline().rstrip().decode('utf-8')]

T = [ord(x)-ord('a') for x in readline().rstrip().decode('utf-8')]



index = [[] for _ in range(26)]

for i,x in enumerate(S):

    index[x].append(i)



LS = len(S)

for x in index:

    if x:

        x.append(x[0] + LS)



ptr = -1 # 最後に使った文字

complete = True

for t in T:

    seq = index[t]

    if not seq:

        complete = False

        break

    i = ptr%LS

    j = bisect_right(seq,i)

    ptr += seq[j]-i



if complete:

    answer = ptr + 1

else:

    answer = -1

print(answer)
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
from bisect import bisect_left

S = input().rstrip()
T = input().rstrip()
LS = len(S)
index = defaultdict(list)  # alphabet to indices
for i, s in enumerate(S):
    index[s].append(i)
index
x = -1  # 今見た場所。次はx+1以上からとる。
for t in T:
    arr = index[t]
    if len(arr) == 0:
        x = -2
        break
    y = (x + 1) % LS
    i = bisect_left(arr, y)
    if i < len(arr):
        next_x = (x + 1) + arr[i] - y
    else:
        next_x = (x + 1) + arr[0] - y + LS
    x = next_x
answer = x + 1
print(answer)

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from bisect import bisect_right

S = [ord(x) - ord("a") for x in readline().rstrip().decode("utf-8")]
T = [ord(x) - ord("a") for x in readline().rstrip().decode("utf-8")]
index = [[] for _ in range(26)]
for i, x in enumerate(S):
    index[x].append(i)
LS = len(S)
for x in index:
    if x:
        x.append(x[0] + LS)
ptr = -1  # 最後に使った文字
complete = True
for t in T:
    seq = index[t]
    if not seq:
        complete = False
        break
    i = ptr % LS
    j = bisect_right(seq, i)
    ptr += seq[j] - i
if complete:
    answer = ptr + 1
else:
    answer = -1
print(answer)

-input = sys.stdin.readline -sys.setrecursionlimit(10**7) -from collections import defaultdict -from bisect import bisect_left +read = sys.stdin.buffer.read +readline = sys.stdin.buffer.readline +readlines = sys.stdin.buffer.readlines +from bisect import bisect_right -S = input().rstrip() -T = input().rstrip() +S = [ord(x) - ord("a") for x in readline().rstrip().decode("utf-8")] +T = [ord(x) - ord("a") for x in readline().rstrip().decode("utf-8")] +index = [[] for _ in range(26)] +for i, x in enumerate(S): +    index[x].append(i) -index = defaultdict(list)  # alphabet to indices -for i, s in enumerate(S): -    index[s].append(i) -index -x = -1  # 今見た場所。次はx+1以上からとる。 +for x in index: +    if x: +        x.append(x[0] + LS) +ptr = -1  # 最後に使った文字 +complete = True -    arr = index[t] -    if len(arr) == 0: -        x = -2 +    seq = index[t] +    if not seq: +        complete = False -    y = (x + 1) % LS -    i = bisect_left(arr, y) -    if i < len(arr): -        next_x = (x + 1) + arr[i] - y -    else: -        next_x = (x + 1) + arr[0] - y + LS -    x = next_x -answer = x + 1 +    i = ptr % LS +    j = bisect_right(seq, i) +    ptr += seq[j] - i +if complete: +    answer = ptr + 1 +else: +    answer = -1