# coding: utf-8

# Your code here!



import sys

sys.setrecursionlimit(10**6)

readline = sys.stdin.readline #文字列入力のときは注意





ss = eval(input())

t = eval(input())



s = ss+ss





l = len(s)

d = [[-1]*26 for _ in range(l)]

#now = [-1]*27

prev = [-1]*27



ans = -1

for i,c in enumerate(s):

#        if now[j] == -1: continue

#        if d[now[j]][ord(c)-97] == -1:

#            d[now[j]][ord(c)-97] = i

    for k in range(max(0,prev[ord(c)-97]),i):

        d[k][ord(c)-97] = i

#    now[ord(c)-97] = i

    prev[ord(c)-97] = i



#print(now)

#print(d)



ans = ss.find(t[0])

if ans == -1:

    print((-1))

    exit()



ls = len(ss)

#print(ans)

lt = len(t)-1



res = ans

for i in range(lt):

#    print(res, d[res])

    if d[res][ord(t[i+1])-97] == -1:

        print((-1))

        exit()

    diff = d[res][ord(t[i+1])-97] - res 

    ans += diff

    res = (res+diff)%ls





print((ans+1))    



    

    



























# coding: utf-8

# Your code here!



import sys

sys.setrecursionlimit(10**6)

readline = sys.stdin.readline #文字列入力のときは注意



s = eval(input())

t = eval(input())

ls = len(s)



ss = s+s



#table[ord(t)-97][i] = 文字tがi番目orそれ以降で登場する最初のindex

table = [[-1]*(ls*2) for _ in range(26)]

prev = [-1]*26

for i,c in enumerate(ss):

    cind = ord(c)-97

    table[cind][prev[cind]+1:i+1] = [i]*(i-prev[cind])

    prev[cind] = i



#print(table)



ans = 0

now = 0

for i in t:

    pos = table[ord(i)-97][now]

    if pos == -1:

        print((-1))

        exit()

    diff = pos +1 - now 

    ans += diff

    now = (now+diff)%ls





print(ans)    



# coding: utf-8
# Your code here!
import sys

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline  # 文字列入力のときは注意
ss = eval(input())
t = eval(input())
s = ss + ss
l = len(s)
d = [[-1] * 26 for _ in range(l)]
# now = [-1]*27
prev = [-1] * 27
ans = -1
for i, c in enumerate(s):
    #        if now[j] == -1: continue
    #        if d[now[j]][ord(c)-97] == -1:
    #            d[now[j]][ord(c)-97] = i
    for k in range(max(0, prev[ord(c) - 97]), i):
        d[k][ord(c) - 97] = i
    #    now[ord(c)-97] = i
    prev[ord(c) - 97] = i
# print(now)
# print(d)
ans = ss.find(t[0])
if ans == -1:
    print((-1))
    exit()
ls = len(ss)
# print(ans)
lt = len(t) - 1
res = ans
for i in range(lt):
    #    print(res, d[res])
    if d[res][ord(t[i + 1]) - 97] == -1:
        print((-1))
        exit()
    diff = d[res][ord(t[i + 1]) - 97] - res
    ans += diff
    res = (res + diff) % ls
print((ans + 1))

# coding: utf-8
# Your code here!
import sys

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline  # 文字列入力のときは注意
s = eval(input())
t = eval(input())
ls = len(s)
ss = s + s
# table[ord(t)-97][i] = 文字tがi番目orそれ以降で登場する最初のindex
table = [[-1] * (ls * 2) for _ in range(26)]
prev = [-1] * 26
for i, c in enumerate(ss):
    cind = ord(c) - 97
    table[cind][prev[cind] + 1 : i + 1] = [i] * (i - prev[cind])
    prev[cind] = i
# print(table)
ans = 0
now = 0
for i in t:
    pos = table[ord(i) - 97][now]
    if pos == -1:
        print((-1))
        exit()
    diff = pos + 1 - now
    ans += diff
    now = (now + diff) % ls
print(ans)

-ss = eval(input()) +s = eval(input()) -s = ss + ss -l = len(s) -d = [[-1] * 26 for _ in range(l)] -# now = [-1]*27 -prev = [-1] * 27 -ans = -1 -for i, c in enumerate(s): -    #        if now[j] == -1: continue -    #        if d[now[j]][ord(c)-97] == -1: -    #            d[now[j]][ord(c)-97] = i -    for k in range(max(0, prev[ord(c) - 97]), i): -        d[k][ord(c) - 97] = i -    #    now[ord(c)-97] = i -    prev[ord(c) - 97] = i -# print(now) -# print(d) -ans = ss.find(t[0]) -if ans == -1: -    print((-1)) -    exit() -ls = len(ss) -# print(ans) -lt = len(t) - 1 -res = ans -for i in range(lt): -    #    print(res, d[res]) -    if d[res][ord(t[i + 1]) - 97] == -1: +ls = len(s) +ss = s + s +# table[ord(t)-97][i] = 文字tがi番目orそれ以降で登場する最初のindex +table = [[-1] * (ls * 2) for _ in range(26)] +prev = [-1] * 26 +for i, c in enumerate(ss): +    cind = ord(c) - 97 +    table[cind][prev[cind] + 1 : i + 1] = [i] * (i - prev[cind]) +    prev[cind] = i +# print(table) +ans = 0 +now = 0 +for i in t: +    pos = table[ord(i) - 97][now] +    if pos == -1: -    diff = d[res][ord(t[i + 1]) - 97] - res +    diff = pos + 1 - now -    res = (res + diff) % ls -print((ans + 1)) +    now = (now + diff) % ls +print(ans)