import bisect



s=eval(input())

t=eval(input())

n=len(s)*2



dic={}

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

  if i in list(dic.keys()):

    dic[i].append(idx)

  else:

    dic[i]=[idx]



#print(dic)

    

ans=k=0

before='-1'

for i in t:

  if i not in list(dic.keys()):

    print((-1))

    exit()

  t=bisect.bisect_left(dic[i], ans%n)

  if before==i:

    t+=1

  if len(dic[i])==t:

    t=0

    k+=n

  ans=dic[i][t]+k

  before=i

  

print((ans+1))
import bisect



s=eval(input())

t=eval(input())

n=len(s)



dic={}

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

  if i in list(dic.keys()):

    dic[i].append(idx)

  else:

    dic[i]=[idx]



ans,p=0,-1

for i in t:

  if i not in list(dic.keys()):

    print((-1))

    exit()

  p=dic[i][bisect.bisect_left(dic[i], p+1)]

  if p>=n:

    p-=n

    ans+=n

  

print((ans+p+1))
import bisect

s = eval(input())
t = eval(input())
n = len(s) * 2
dic = {}
for idx, i in enumerate(s * 2):
    if i in list(dic.keys()):
        dic[i].append(idx)
    else:
        dic[i] = [idx]
# print(dic)
ans = k = 0
before = "-1"
for i in t:
    if i not in list(dic.keys()):
        print((-1))
        exit()
    t = bisect.bisect_left(dic[i], ans % n)
    if before == i:
        t += 1
    if len(dic[i]) == t:
        t = 0
        k += n
    ans = dic[i][t] + k
    before = i
print((ans + 1))

import bisect

s = eval(input())
t = eval(input())
n = len(s)
dic = {}
for idx, i in enumerate(s * 2):
    if i in list(dic.keys()):
        dic[i].append(idx)
    else:
        dic[i] = [idx]
ans, p = 0, -1
for i in t:
    if i not in list(dic.keys()):
        print((-1))
        exit()
    p = dic[i][bisect.bisect_left(dic[i], p + 1)]
    if p >= n:
        p -= n
        ans += n
print((ans + p + 1))

-n = len(s) * 2 +n = len(s) -# print(dic) -ans = k = 0 -before = "-1" +ans, p = 0, -1 -    t = bisect.bisect_left(dic[i], ans % n) -    if before == i: -        t += 1 -    if len(dic[i]) == t: -        t = 0 -        k += n -    ans = dic[i][t] + k -    before = i -print((ans + 1)) +    p = dic[i][bisect.bisect_left(dic[i], p + 1)] +    if p >= n: +        p -= n +        ans += n +print((ans + p + 1))