import collections

import bisect

S = eval(input())

T = eval(input())

N = len(S)



d = collections.defaultdict(list)

for i, s in enumerate(S):

    d[s].append(i + 1)



ans = 0

end = 0

isOK = True

i = 0



for t in T:

    if len(d[t]) == 0:

        isOK = False

        break

    dic = d[t]

    idx = bisect.bisect_right(dic, i)

    if len(dic) == idx:

        i = dic[0]

        end += 1

    else:

        i = dic[idx]



if isOK:

    ans = N * end + i

else:

    ans = -1



print(ans)

from collections import defaultdict

import bisect



S = eval(input())

T = eval(input())



d = defaultdict(list)

for i, s in enumerate(S, start=1):

    d[s].append(i)



ans = 0

i = 0



for t in T:

    if not d[t]:

        print((-1))

        exit()



    if i >= d[t][-1]:

        ans += len(S)

        i = d[t][0]

        continue



    pos = bisect.bisect_right(d[t], i)

    i = d[t][pos]



ans += i

print(ans)

import collections
import bisect

S = eval(input())
T = eval(input())
N = len(S)
d = collections.defaultdict(list)
for i, s in enumerate(S):
    d[s].append(i + 1)
ans = 0
end = 0
isOK = True
i = 0
for t in T:
    if len(d[t]) == 0:
        isOK = False
        break
    dic = d[t]
    idx = bisect.bisect_right(dic, i)
    if len(dic) == idx:
        i = dic[0]
        end += 1
    else:
        i = dic[idx]
if isOK:
    ans = N * end + i
else:
    ans = -1
print(ans)

from collections import defaultdict
import bisect

S = eval(input())
T = eval(input())
d = defaultdict(list)
for i, s in enumerate(S, start=1):
    d[s].append(i)
ans = 0
i = 0
for t in T:
    if not d[t]:
        print((-1))
        exit()
    if i >= d[t][-1]:
        ans += len(S)
        i = d[t][0]
        continue
    pos = bisect.bisect_right(d[t], i)
    i = d[t][pos]
ans += i
print(ans)

-import collections +from collections import defaultdict -N = len(S) -d = collections.defaultdict(list) -for i, s in enumerate(S): -    d[s].append(i + 1) +d = defaultdict(list) +for i, s in enumerate(S, start=1): +    d[s].append(i) -end = 0 -isOK = True -    if len(d[t]) == 0: -        isOK = False -        break -    dic = d[t] -    idx = bisect.bisect_right(dic, i) -    if len(dic) == idx: -        i = dic[0] -        end += 1 -    else: -        i = dic[idx] -if isOK: -    ans = N * end + i -else: -    ans = -1 +    if not d[t]: +        print((-1)) +        exit() +    if i >= d[t][-1]: +        ans += len(S) +        i = d[t][0] +        continue +    pos = bisect.bisect_right(d[t], i) +    i = d[t][pos] +ans += i