import bisect

s = list(eval(input()))

t = list(eval(input()))

n = len(s)

m = len(t)

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

for i in range(n):

  alphabet[ord(s[i])-ord('a')] += [i] 

loop = 0

pre = -1

for i in range(m):

  c = ord(t[i]) - ord('a')

  if len(alphabet[c]) == 0:

    print((-1))

    exit()

  idx = bisect.bisect_left(alphabet[c], pre+1)

  if idx == len(alphabet[c]):

    loop += 1

    pre = alphabet[c][0]

  else:

    pre = alphabet[c][idx]



print((pre + loop * n + 1))
import bisect

s = list(eval(input()))

t = list(eval(input()))



if len(set(t)-set(s)) > 0:

  print((-1))

  exit()



c = set(s)

dic = {}

for char in c:

  dic[char] = []



for i in range(len(s)):

  dic[s[i]] += [i]



last = -1

r = 0

for char in t:

  tmp = last

  idx = bisect.bisect_right(dic[char], last)

  if idx < len(dic[char]):

    last = dic[char][idx]



  if tmp == last:

    r += 1

    last = dic[char][0]



print((len(s)*r + last + 1))

import bisect

s = list(eval(input()))
t = list(eval(input()))
n = len(s)
m = len(t)
alphabet = [[] for _ in range(26)]
for i in range(n):
    alphabet[ord(s[i]) - ord("a")] += [i]
loop = 0
pre = -1
for i in range(m):
    c = ord(t[i]) - ord("a")
    if len(alphabet[c]) == 0:
        print((-1))
        exit()
    idx = bisect.bisect_left(alphabet[c], pre + 1)
    if idx == len(alphabet[c]):
        loop += 1
        pre = alphabet[c][0]
    else:
        pre = alphabet[c][idx]
print((pre + loop * n + 1))

import bisect

s = list(eval(input()))
t = list(eval(input()))
if len(set(t) - set(s)) > 0:
    print((-1))
    exit()
c = set(s)
dic = {}
for char in c:
    dic[char] = []
for i in range(len(s)):
    dic[s[i]] += [i]
last = -1
r = 0
for char in t:
    tmp = last
    idx = bisect.bisect_right(dic[char], last)
    if idx < len(dic[char]):
        last = dic[char][idx]
    if tmp == last:
        r += 1
        last = dic[char][0]
print((len(s) * r + last + 1))

-n = len(s) -m = len(t) -alphabet = [[] for _ in range(26)] -for i in range(n): -    alphabet[ord(s[i]) - ord("a")] += [i] -loop = 0 -pre = -1 -for i in range(m): -    c = ord(t[i]) - ord("a") -    if len(alphabet[c]) == 0: -        print((-1)) -        exit() -    idx = bisect.bisect_left(alphabet[c], pre + 1) -    if idx == len(alphabet[c]): -        loop += 1 -        pre = alphabet[c][0] -    else: -        pre = alphabet[c][idx] -print((pre + loop * n + 1)) +if len(set(t) - set(s)) > 0: +    print((-1)) +    exit() +c = set(s) +dic = {} +for char in c: +    dic[char] = [] +for i in range(len(s)): +    dic[s[i]] += [i] +last = -1 +r = 0 +for char in t: +    tmp = last +    idx = bisect.bisect_right(dic[char], last) +    if idx < len(dic[char]): +        last = dic[char][idx] +    if tmp == last: +        r += 1 +        last = dic[char][0] +print((len(s) * r + last + 1))