S = eval(input())

T = eval(input())

dic = {}

for i,s in enumerate(S):

  if s not in dic:

    dic[s] = [i]

  else:

    dic[s].append(i)

#print(dic)

ind = -1

loop = 0

import bisect

for t in T:

  if t not in dic:

    ans = -1

    break

  if dic[t][-1]<=ind:

    loop += 1

    ind = dic[t][0]

  else:

    i = bisect.bisect_right(dic[t],ind)

    ind = dic[t][i]

  #print(ind)

#print(loop,ind)

else:

  ans = len(S)*loop+ind+1

          

print(ans)   



#print(*ans[1:], sep='\n')

from bisect import *

def alph_to_num(s):

  return ord(s)-ord('a')

def solve():

  ans = 0

  S = eval(input())

  T = eval(input())

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

  for i,s in enumerate(S):

    lis[alph_to_num(s)].append(i)

  ind = -1

  for t in T:

    n = alph_to_num(t)

    if not len(lis[n]):

      return -1

    if ind>=lis[n][-1]:

      ans += len(S)

      ind = lis[n][0]

    else:

      ind = lis[n][bisect_right(lis[n],ind)]

  ans += ind+1

  return ans

print((solve()))
S = eval(input())
T = eval(input())
dic = {}
for i, s in enumerate(S):
    if s not in dic:
        dic[s] = [i]
    else:
        dic[s].append(i)
# print(dic)
ind = -1
loop = 0
import bisect

for t in T:
    if t not in dic:
        ans = -1
        break
    if dic[t][-1] <= ind:
        loop += 1
        ind = dic[t][0]
    else:
        i = bisect.bisect_right(dic[t], ind)
        ind = dic[t][i]
    # print(ind)
# print(loop,ind)
else:
    ans = len(S) * loop + ind + 1
print(ans)
# print(*ans[1:], sep='\n')

from bisect import *


def alph_to_num(s):
    return ord(s) - ord("a")


def solve():
    ans = 0
    S = eval(input())
    T = eval(input())
    lis = [[] for _ in range(26)]
    for i, s in enumerate(S):
        lis[alph_to_num(s)].append(i)
    ind = -1
    for t in T:
        n = alph_to_num(t)
        if not len(lis[n]):
            return -1
        if ind >= lis[n][-1]:
            ans += len(S)
            ind = lis[n][0]
        else:
            ind = lis[n][bisect_right(lis[n], ind)]
    ans += ind + 1
    return ans


print((solve()))

-S = eval(input()) -T = eval(input()) -dic = {} -for i, s in enumerate(S): -    if s not in dic: -        dic[s] = [i] -    else: -        dic[s].append(i) -# print(dic) -ind = -1 -loop = 0 -import bisect +from bisect import * -for t in T: -    if t not in dic: -        ans = -1 -        break -    if dic[t][-1] <= ind: -        loop += 1 -        ind = dic[t][0] -    else: -        i = bisect.bisect_right(dic[t], ind) -        ind = dic[t][i] -    # print(ind) -# print(loop,ind) -else: -    ans = len(S) * loop + ind + 1 -print(ans) -# print(*ans[1:], sep='\n') + +def alph_to_num(s): +    return ord(s) - ord("a") + + +def solve(): +    ans = 0 +    S = eval(input()) +    T = eval(input()) +    lis = [[] for _ in range(26)] +    for i, s in enumerate(S): +        lis[alph_to_num(s)].append(i) +    ind = -1 +    for t in T: +        n = alph_to_num(t) +        if not len(lis[n]): +            return -1 +        if ind >= lis[n][-1]: +            ans += len(S) +            ind = lis[n][0] +        else: +            ind = lis[n][bisect_right(lis[n], ind)] +    ans += ind + 1 +    return ans + + +print((solve()))