CodeEff/ECCO huggingface dataset:
# Original solution
n,x = list(map(int,input().split()))
m = [int(eval(input())) for i in range(n)]
x -= sum(m)
print((x//min(m)+n))

# Optimized solution
n, x = list(map(int, input().split()))
m = [int(eval(input())) for _ in range(n)]
x -= sum(m)
print((n + x // min(m)))
# Original solution
n, x, *m = list(map(int, open(0).read().split()))
ans = 0
for i in sorted(m):
    if x>=i:
        x -= i
        ans+=1
mx = min(m)
print((ans + (x//mx)))

# Optimized solution
n, x, *m = list(map(int, open(0).read().split()))
ans = 0
for i in sorted(m):
    if x>=i:
        x -= i
        ans+=1
print((ans+x//min(m)))
# Original solution
N, X = list(map(int, input().split()))

mn = [0]*N
for i in range(N):
  mn[i] = int(eval(input()))
  
ans = N
x = X - sum(mn)

while(x >= min(mn)):
  if x // min(mn) == 0:
    mn[mn.index(min(mn))] = 1000000
  else:
    if x >= min(mn):
      x -= min(mn)
      ans += 1
      
print(ans)

# Optimized solution
N, X = list(map(int, input().split()))

mn = [0]*N
for i in range(N):
  mn[i] = int(eval(input()))
  
ans = N
x = X - sum(mn)

while(x >= min(mn)):
  if x // min(mn) == 0:
    mn[mn.index(min(mn))] = 1000000
  else:
    x -= min(mn)
    ans += 1
      
print(ans)
# Original solution
n, x = list(map(int, input().split()))
m = []
for i in range(n):
    m.append(int(eval(input())))
count = 0
a = min(m)
s = sum(m)

x -= s
count += n

while x >= a:
    x -= a
    count += 1

print(count)

# Optimized solution
n, x = list(map(int, input().split()))
m = [int(eval(input())) for _ in range(n)]

x -= sum(m)
count = n

mincost = 10**5
for i in range(n):
    mincost = min(mincost, m[i])

count += x // mincost
print(count)
# Original solution
n, m = list(map(int, input().split()))
ls = [int(eval(input())) for _ in range(n)]
ls.sort()

m -= sum(ls)
cnt = n

while True:
    if m >= ls[0]:
        m -= ls[0]
        cnt += 1
    else:
        break

print(cnt)


# Optimized solution
n, m = list(map(int, input().split()))
ls = [int(eval(input())) for _ in range(n)]
print((n+((m-sum(ls))//min(ls))))
# Original solution
N,X = list(map(int,input().split()))
M = [int(eval(input())) for _ in range(N)]
print((N + (X-sum(M))//min(M)))

# Optimized solution
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N,X = list(map(int,input().split()))
M = [int(eval(input())) for _ in range(N)]

r = X - sum(M)
print((N + r//min(M)))
# Original solution
n,x=list(map(int,input().split()))
ln=[int(eval(input())) for i in range(n)]
print((n+(x-sum(ln))//min(ln)))

# Optimized solution
n,x=list(map(int,input().split()))
ln=[int(eval(input())) for _ in range(n)]
print((n+(x-sum(ln))//min(ln)))
# Original solution
n,x = list(map(int,input().split()))
m = list(int(eval(input())) for i in range(n))
m.sort()

z = sum(m)
s = n

while x > z:
    z += m[0]
    if x >= z:
        s += 1

print(s)

# Optimized solution
n,x = list(map(int,input().split()))
m = list(int(eval(input())) for i in range(n))
m.sort()
z = sum(m)
print((n+(x-z)//m[0]))
# Original solution
n,x=list(map(int, input().split()))
min_cost=float('inf')
cnt=0
for i in range(n):
    mi = int(eval(input()))
    x -= mi
    cnt += 1
    min_cost = min(min_cost,mi)
while x >= min_cost:
    x -= min_cost
    cnt += 1
print(cnt)

# Optimized solution
n,x = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(n)]
print((len(l)+(x-sum(l))//min(l)))
# Original solution
N, X = [int(x) for x in input().split()]

list01=[]
for i in range(N):
  j = int(eval(input()))
  list01.append(j)
 
j = 0
mass = sum(list01)

while mass <= X:
  j += 1
  mass = sum(list01) + min(list01) * j

print((N + j -1))

# Optimized solution
N, X = [int(x) for x in input().split()]

list01 = []
for i in range(N):
  i = int(eval(input()))
  list01.append(i)

min_01 = 0
for i in range(len(list01)):
  if min_01 == 0:
    min_01 = list01[i]
  elif list01[i] < min_01:
    min_01 = list01[i]
  
for i in range(len(list01)):
  X -= list01[i]
    
print((X // min_01 + N))
# Original solution
N, X = list(map(int, input().split()))
M = [int(eval(input())) for _ in range(N)]
Ms = sorted(M)
print((len(Ms) + (X-sum(Ms))//Ms[0]))

# Optimized solution
N, X = list(map(int, input().split()))
M = [int(eval(input())) for _ in range(N)]
print((len(M) + (X-sum(M))//min(M)))
# Original solution
n,x = list(map(int,input().split()))
m = [int(eval(input())) for _ in range(n)]
ans = 0
minm = 1000
for i in range(n):
    x -= m[i]
    minm = min(minm,m[i])
    ans += 1
while x >= minm:
    x -= minm
    ans += 1
print(ans)

# Optimized solution
n,x = list(map(int,input().split()))
m = [int(eval(input())) for _ in range(n)]
x -= sum(m)
ans = n + x//min(m)
print(ans)
# Original solution
from functools import lru_cache
import sys

sys.setrecursionlimit(1000000)

@lru_cache(maxsize=1000000)
def dp(rest,score):
    ansbox=[]
    scorebox=[]
    for i in m_list:
        if (rest-i)>0:
            ansbox.append(dp(rest-i,score+1))
            scorebox.append(dp(rest-i, score+1)[1])
    if ansbox:
        max_index=scorebox.index(max(scorebox))
        return ansbox[max_index][0],ansbox[max_index][1]
    else:

        return rest,score
    pass

N,X=list(map(int,input().split()))
m_list=[]
newX=X
sum=0
for i in range(N):
    inp=int(eval(input()))
    m_list.append(inp)
    newX-=inp

score=dp(newX,N)

print((score[1]))


# Optimized solution
N,X=list(map(int,input().split()))
M=[int(eval(input())) for _ in range(N)]
print((len(M)+(X-sum(M))//min(M)))
# Original solution
n,x = list(map(int,input().split()))
l = []
s = 0
for i in range(n):
    l.append(int(eval(input())))
    s += l[i]
    
for j in range(0,100000):
    if (x-s) == 0:
        print(n)
        break
    elif ((x-s)/(min(l)*(j+1))) < 1:
        print((n+j))
        break

# Optimized solution
n,x = list(map(int,input().split()))
l = []
s = 0
for i in range(n):
    l.append(int(eval(input())))
    s += l[i]
print((int(n+(x-s)/min(l))))
# Original solution
num, beaking = list(map(int, input().split()))
list_category = [int(eval(input())) for i in range(num)]
nokori = beaking - sum(list_category)
nokori_num = nokori // min(list_category)

total = num + nokori_num
print(total)

# Optimized solution
n, x  = list(map(int, input().split()))
arr = [int(eval(input())) for i in range(n)]
x = x - sum(arr)
print(((x // min(arr)) + n))
# Original solution
n,x = list(map(int,input().split()))
m = [int(eval(input())) for i in range(n)]
a = n
s = sum(m) 
while s < x:
    s+=min(m)
    a += 1
print(([a,a-1][s>x]))


# Optimized solution
n,x = list(map(int,input().split()))
m = list(int(eval(input())) for i in range(n))
x -= sum(m)
print((x//min(m)+n))
# Original solution
n, x = list(map(int, input().split()))
M = []
for _ in range(n):
    M.append(int(eval(input())))

M.sort()
cnt = 0
for m in M:
  x -= m
  cnt += 1

while x > 0:
    x -= M[0]
    if x >= 0:
        cnt += 1


print(cnt)


# Optimized solution
n,x=list(map(int, input().split()))
m = [int(eval(input())) for _ in range(n)]
ans = n
m.sort()
x -=sum(m)
while x > 0:
    x -= m[0]
    if x >= 0:
        ans += 1
print(ans)
# Original solution
N, X = list(map(int, input().split()))
list = []
for i in range(N):
  m = int(eval(input()))
  list.append(m)
  
print((N + (X - sum(list)) // min(list)))

# Optimized solution
N, X = list(map(int, input().split()))
m = [int(eval(input())) for _ in range(N)]  
print((N + (X - sum(m)) // min(m)))
# Original solution
n, x = list(map(int, input().split()))
cnt = 0

m = [int(eval(input())) for _ in range(n)]
M = sorted(m)
if sum(m) <= x:
    cnt += (n +(x - sum(m)) // min(m))
else:
    while x >= 0:
        for i in range(n):
            x -= M[i]
            cnt += 1
print(cnt)

# Optimized solution
n, x = list(map(int, input().split()))
m = [int(eval(input())) for i in range(n)]
l = []
for i in range(n):
    X = (x - sum(m)) // m[i]
    l.append(X)
    
print((n + max(l)))
# Original solution
N, X = list(map(int, input().split()))
M = [int(eval(input())) for i in range(N)]
cnt = 0
for i in M:
    X -= i
    cnt += 1
while True:
    X -= min(M)
    if X < 0:
        break
    cnt += 1
print(cnt)

# Optimized solution
N, X = list(map(int, input().split()))
M = [int(eval(input())) for i in range(N)]
cnt = N
X -= sum(M)
cnt += X // min(M)
print(cnt)
# Original solution
N,X = list(map(int,input().split()))
M = []
for i in range(N) :
    m = int(eval(input()))
    M.append(m)
ans = N
X -= sum(M)
while X >= min(M) :
    ans += 1
    X -= min(M)
print(ans)



# Optimized solution
N,X = list(map(int,input().split()))
M = []
for i in range(N) :
    M.append(int(eval(input())))

ans = ((X-sum(M))//min(M))+N
print(ans)
# Original solution
N, X = list(map(int,input().split()))
M = [int(eval(input())) for _ in range(N)]
tmp = X - sum(M)
if(tmp == 0):
  print(N)
else:
  print((tmp//min(M) + N))

# Optimized solution
N, X = list(map(int,input().split()))
M = [int(eval(input())) for _ in range(N)]
X = X - sum(M)
cnt = N
x = X
tmp = 0
for m in M:
  tmp = max(tmp, x//m)
print((tmp+cnt))
# Original solution
n, x = list(map(int, input().split()))
ls = [int(eval(input())) for _ in range(n)]
x -= sum(ls)
print((n + x // min(ls)))

# Optimized solution
n, x = list(map(int, input().split()))
ls = [int(eval(input())) for _ in range(n)]
print((n + (x - sum(ls)) // min(ls)))
# Original solution
n, x = list(map(int, input().split()))
m = [int(eval(input())) for i in range(n)]
sum = 0
min = 1000000
for i in range(n):
    sum+=m[i]
    if min > m[i]: min = m[i]
x-=sum
print((n+int(x/min)))

# Optimized solution
n, x = list(map(int, input().split()))
m = [int(eval(input())) for i in range(n)]
sum = 0
for i in range(n):
    sum+=m[i]
x-=sum
print((n+int(x/min(m))))
# Original solution
N,X = list(map(int,input().split()))
a = [int(eval(input())) for i in range(N)]
moto = X - sum(a)
ans = N
while moto >= min(a):
	ans += 1
	moto = moto - min(a)
print(ans)

# Optimized solution
N,X = list(map(int,input().split()))
a = [int(eval(input())) for i in range(N)]
ans = N + (X - sum(a)) // min(a)
print(ans)
# Original solution
n, x = input().split()
n = int(n)
x = int (x)
m = []
i_min = 0 
result = 0

for i in range(n):
 m.append(int(eval(input())))

for i in range(len(m)):
 x = x - m[i]
 result = result + 1

for i in range(len(m)):
 if m[i_min] > m[i]:
   i_min = i

for i in range(x):
 if x >= m[i_min]:
  result = result + 1
  x = x - m[i_min]
 else:
  break

print(result)

# Optimized solution
#NとXの読み込み
n, x = input().split()
n = int(n)
x = int (x)
m = []
i_min = 0 
result = 0

#m1からmnまでの読み込み
for i in range(n):
 m.append(int(eval(input())))
#全種類ひとつずつ作る
for i in range(len(m)):
 x = x - m[i]
 result = result + 1
#リストの中の最小値を突き止める
for i in range(len(m)):
 if m[i_min] > m[i]:
   i_min = i
#i_minを作れるだけ作る
for i in range(x):
 if x >= m[i_min]:
  result = result + 1
  x = x - m[i_min]
 else:
  break
#印刷
print(result)
# Original solution
#NとXの読み込み
n, x = input().split()
n = int(n)
x = int (x)
m = []
i_min = 0 
result = 0

#m1からmnまでの読み込み
for i in range(n):
 m.append(int(eval(input())))
#全種類ひとつずつ作る
for i in range(len(m)):
 x = x - m[i]
 result = result + 1
#リストの中の最小値を突き止める
for i in range(len(m)):
 if m[i_min] > m[i]:
   i_min = i
#i_minを作れるだけ作る
for i in range(x):
 if x >= m[i_min]:
  result = result + 1
  x = x - m[i_min]
 else:
  break
#印刷
print(result)


# Optimized solution
#データの読み込み
n, x = input().split()
n = int(n)
x = int(x)
m = []
i_min = 0
gokei = 0
#n個の入力に対するループ
for i in range(n):
  #問題からの入力をintに変換してリストへ格納
  m.append(int(eval(input())))
  #全部を1つずつ作った場合の粉量の合計
  gokei = gokei + m[i]
  #使う粉量が一番少ないドーナツを見つける
  if m[i_min] > m[i]:
    i_min = i
#全部を1つずつ作った後に残る粉量
x = x - gokei
print((int(x/m[i_min]) + n))
# Original solution
a, b, c = list(map(int, input().split()))
n=0
while True:
    if c%a == 0:
        n += 1
    a += 1
    if a == b:
        break
print(n)



# Optimized solution
a, b, c = list(map(int, input().split()))
n=0
while True:
    if c%a == 0:
        n += 1
    a += 1
    if a > b:
        break
print(n)
# Original solution
a,b,c = [int(x) for x in input().split( )]
div = []
for x in range(1,c+1):
    if c % x == 0:
        div.append(x)
r = []
for x in range(a,b+1):
    r.append(x)
answer = 0
for x in div:
    for y in r:
        if x == y:
            answer += 1
print(answer)


# Optimized solution
a,b,c = [int(x) for x in input().split( )]
count = 0
for number in range(a,b+1):
    if c % number == 0:
        count += 1
print(count)
# Original solution
a,b,c=list(map(int,input().split(" ")))
count=0
while(1):
    if c%a==0:
        count+=1
    a+=1
    
    if a==b:
        break
    
print(count)




# Optimized solution
a,b,c=list(map(int,input().split(" ")))
count=0
while(a<=b):
    if c%a==0:
        count+=1
    a+=1

print(count)
# Original solution
from operator import add
from functools import reduce

def divisor_generator(a, b, c):
    for i in range(a, b+1):
        yield (1 if c%i == 0 else 0)

a, b, c = list(map(int, input().split(' ')))

print((reduce(add, divisor_generator(a, b, c))))

# Optimized solution
a, b, c = list(map(int, input().split()))

cnt = 0
for n in range(a, b+1):
    if c % n == 0:
        cnt += 1

print(cnt)
# Original solution
import sys

a, b, c = [ int( val ) for val in sys.stdin.readline().split( ' ' ) ]
cnt = 0
i = a
while i <= b:
	if ( c % i ) == 0:
		cnt += 1
	i += 1
print(( "{}".format( cnt ) ))

# Optimized solution
import sys

a, b, c = [ int( val ) for val in sys.stdin.readline().split( ' ' ) ]
cnt = 0
for divisor in range( a, b+1 ):
    if ( c % divisor ) == 0:
        cnt += 1
print(( "{}".format( cnt ) ))
# Original solution
a, b, c = list(map(int, input().split()))
cnt = 0
for i in range(a, b+1):
    if c % i == 0:
        cnt += 1
print(cnt)

# Optimized solution
a, b, c = list(map(int, input().split()))
divisor = 0
for n in range(a, b+1):
    if c % n == 0:
        divisor += 1
print(divisor)
# Original solution
import math
a, b, c = list(map(int, input().split()))
l = []; d = int(math.sqrt(c)); e = 0
for i in range(1, d + 1):
	if i * i == c: l += [i]
	elif c % i == 0: l += [i, c // i]
for x in l:
	if a <= x <= b: e += 1
print(e)

# Optimized solution
a, b, c = list(map(int, input().split()))
ans = 0
for i in range(a, b + 1):
	if c % i == 0:
		ans += 1
print(ans)
# Original solution
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)

# Optimized solution
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)
# Original solution
S = list([ord(x)-ord('a') for x in input().strip()])
T = list([ord(x)-ord('a') for x in input().strip()])

L = len(S)

occ = [[] for i in range(26)]
for i, c in enumerate(S):
    occ[c].append(i)

for c in T:
    if occ[c] == []:
        print((-1))
        quit()

total = 0
cur = -1

def getLowest(bound, lo, hi, lst):
    # Return index of lowest element in list greater than bound
    if lo >= hi:
        if lst[lo] > bound:
            return lo
        else:
            return 0
        
    mid = lo + (hi - lo) // 2
    if lst[mid] > bound:
        return getLowest(bound, lo, mid, lst)
    else:
        return getLowest(bound, mid+1, hi, lst)

for i, char in enumerate(T):
    newpos = occ[char][getLowest(cur, 0, len(occ[char])-1, occ[char])]
    if cur == newpos:
        total += L
    elif newpos < cur:
        total += L - cur + newpos
    else:
        total += newpos - cur
    cur = newpos
print(total)
    


# Optimized solution
S = list([ord(x)-ord('a') for x in input().strip()])
T = list([ord(x)-ord('a') for x in input().strip()])

L = len(S)

occ = [[] for i in range(26)]
for i, c in enumerate(S):
    occ[c].append(i)

for c in T:
    if occ[c] == []:
        print((-1))
        quit()

total = 0
cur = -1

def getLowest(bound, lo, hi, lst):
    # Return lowest element in list greater than bound
    while lo < hi:
        mid = lo + (hi - lo) // 2
        if lst[mid] > bound:
            hi = mid
        else:
            lo = mid + 1
    if lst[lo] > bound:
        return lst[lo]
    return lst[0]
        
    

for i, char in enumerate(T):
    newpos = getLowest(cur, 0, len(occ[char])-1, occ[char])
    if cur == newpos:
        total += L
    elif newpos < cur:
        total += L - cur + newpos
    else:
        total += newpos - cur
    cur = newpos
print(total)
# Original solution
from bisect import bisect_right
from collections import defaultdict
import sys
read = sys.stdin.readline

s = read()[:-1]
t = read()[:-1]
# 即時終了
if set(t) - set(s):
    print((-1))
    exit()

# 前処理
# 0based indexにおいてi文字目以降に文字cが出てくるidxを取得する

# 前処理の前処理、0文字目から見たときにその文字が何文字目にあるかを記録しておく
mojiidx = defaultdict(lambda: [])
for i, ss in enumerate(s + s):
    mojiidx[ss].append(i)

# i文字目において、次に文字cが出てくるのは何文字あと？
skiptable = []
for i in range(0, len(s)):
    tmp = {}
    for c, ls in list(mojiidx.items()):
        tmp[c] = ls[bisect_right(ls, i)] - i
    skiptable.append(tmp)

# print(skiptable)

# 本処理
# 最初にうまく飛べる点を探索
for i, ss in enumerate(s):
    if ss == t[0]:
        now = i
        break

for tt in t[1:]:
    idx = now % len(s)
    now += skiptable[idx][tt]
print((now + 1))

# Optimized solution

from bisect import bisect_right
from collections import defaultdict
import sys
read = sys.stdin.readline

s = read()[:-1]
t = read()[:-1]
# 即時終了
if set(t) - set(s):
    print((-1))
    exit()

# 前処理
# 0文字目から見たときにその文字が何文字目にあるかを記録しておく
mojiidx = defaultdict(lambda: [])
for i, ss in enumerate(s + s):
    mojiidx[ss].append(i)

# 本処理
# 最初にうまく飛べる点を探索
for i, ss in enumerate(s):
    if ss == t[0]:
        now = i
        break

for tt in t[1:]:
    idx = now % len(s)
    # 前処理の列から文字ttが何文字あとに出現するかを探索する
    ls = mojiidx[tt]
    tmp = ls[bisect_right(ls, idx)] - idx
    now += tmp
print((now + 1))
# Original solution
#ABC138-E Strings of Impurity
"""
sの好きなだけのループに対する部分文字列tを求める
tにあってsにない文字がある時点でno
そうでないならば必ず達成可能で、
tに対してループを回し(i)、
sのj文字目に関して、それより後に初めて出てくるt[i+1]の場所をindexで返し,i+=1,j=そのindex
にする。
そのようなindexがないならば、j=0とし、またはじめから回す。
"""
import sys
import bisect
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

s = readline().rstrip().decode('utf-8')
t = readline().rstrip().decode('utf-8')
s_s = set(list(s))
t_s = set(list(t))
flag = 1 if s_s & t_s == t_s else 0

if not flag:
    print((-1))
    exit()

#2進数で、
lst1 = [[] for _ in range(26)]
kijun = ord("a")
for idx,i in enumerate(s):
    lst1[ord(i)-kijun].append(idx)

i = 0
roop = 0
count = 0
while True:
    if i >= len(t):
        print((roop*len(s)+count)) #countは0-indexedの為
        break
    now = ord(t[i])-kijun
    res = bisect.bisect_left(lst1[now],count)
    if res == len(lst1[now]):
        roop += 1
        count = 0
        res = bisect.bisect_left(lst1[now],count)
        count = lst1[now][res]+1 #その次の文字から
    else:
        count = lst1[now][res]+1
    i += 1
    

# Optimized solution
#ABC138-E Strings of Impurity
"""
sの好きなだけのループに対する部分文字列tを求める
tにあってsにない文字がある時点でno
そうでないならば必ず達成可能で、
tに対してループを回し(i)、
sのj文字目に関して、それより後に初めて出てくるt[i+1]の場所をindexで返し,i+=1,j=そのindex
にする。
そのようなindexがないならば、j=0とし、またはじめから回す。
"""
import sys
import bisect
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

s = readline().rstrip().decode('utf-8')
t = readline().rstrip().decode('utf-8')
s_s = set(list(s))
t_s = set(list(t))
flag = 1 if s_s & t_s == t_s else 0

if not flag:
    print((-1))
    exit()

#lst1:各アルファベットごとに、何番目に出てくるか
lst1 = [[] for _ in range(26)]
kijun = ord("a")
for idx,i in enumerate(s):
    lst1[ord(i)-kijun].append(idx)

i = 0
roop = 0
count = 0
while True:
    if i >= len(t):
        print((roop*len(s)+count))
        break
    now = ord(t[i])-kijun
    res = bisect.bisect_left(lst1[now],count)
    if res == len(lst1[now]):
        roop += 1
        count = 0
        res = bisect.bisect_left(lst1[now],count)
        count = lst1[now][res]+1 #その次の文字から
    else:
        count = lst1[now][res]+1
    i += 1
# Original solution
from collections import defaultdict
from bisect import bisect_left

S = input().rstrip()
T = input().rstrip()

LS = len(S)
index = defaultdict(list)

for i, s in enumerate(S):
  index[s].append(i)
  
x = -1
for t in T:
  arr = index[t]
  if len(arr) == 0:
    print((-1))
    exit()
  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] + LS - y
  x = next_x
ans = x+1
print(ans)

# Optimized solution
from collections import defaultdict
from bisect import *
 
S = input().rstrip()
T = input().rstrip()
 
LS = len(S)
index = defaultdict(list)
 
for i, s in enumerate(S):
  index[s].append(i)

x = -1
loop = 0
for t in T:
  arr = index[t]  
  if len(arr) == 0:
    print((-1))
    exit()  
  i = bisect(arr, x)  
  if i == len(arr):
    loop += 1
    x = arr[0]
  else:
    x = arr[i]

print((loop*LS+x+1))
# Original solution
import sys
from collections import defaultdict
import bisect
sys.setrecursionlimit(10 ** 7)

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

S = sr()
len_S = len(S)
T = sr()
dict_S = defaultdict(list)
for i, s in enumerate(S):
    dict_S[s].append(i)

answer = 0
cur = -1
for t in T:
    turn = 0 # 1周した時 len_S - cur
    if not dict_S[t]:
        print((-1))
        exit()
    indexes = dict_S[t] + [len_S]
    i = bisect.bisect_right(indexes, cur)
    next = indexes[i]
    if next == len_S:
        turn = len_S - cur - 1
        cur = -1
        answer += indexes[0] - cur + turn
        cur = indexes[0]
    else:
        answer += next - cur
        cur = next

print(answer)


# Optimized solution
import sys
from collections import defaultdict
import bisect
sys.setrecursionlimit(10 ** 7)

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

S = sr()
T = sr()
len_S = len(S)
indexes_S = defaultdict(list)
for i, s in enumerate(S):
    indexes_S[s].append(i)

x = -1 # 今いるところ、次はx+1から探索
for t in T:
    if len(indexes_S[t]) == 0:
        print((-1)); exit()
    arr = indexes_S[t]
    y = (x+1) % len_S
    next_i = bisect.bisect_left(arr, y) # tの同じ文字がある次のindex
    if next_i < len(arr):
        x = (x+1) + arr[next_i] - y
    else:
        x = (x+1) + arr[0] + len_S - y # 1周して次のarr

print((x+1))