from collections import defaultdict

import bisect



d=defaultdict(list)



s=eval(input())

t=eval(input())



ns=len(s)

nt=len(t)



for i in range(ns):

  d[s[i]].append(i)



for k,v in list(d.items()):

  d[k].append(ns)

#print(d)



ans=0

cnt=-1



for i in range(nt):

  tt=d[t[i]]

#  print(t[i],tt,ans,cnt)

  if tt==[]:

    print((-1))

    exit(0)

  else:

    a=bisect.bisect_right(tt,cnt)

#    print("ind",a)

    if tt[a]==ns:

      ans+=ns+tt[0]-cnt

      cnt=tt[0]

    else:

      ans+=tt[a]-cnt

      cnt=tt[a]

      

print(ans)

      
import sys

#input = sys.stdin.readline

input = sys.stdin.buffer.readline



# mod=10**9+7

# rstrip().decode('utf-8')

# map(int,input().split())

# import numpy as np



from collections import defaultdict

import bisect



def main():

	s=input().rstrip().decode('utf-8')

	t=input().rstrip().decode('utf-8')



	D=defaultdict(list)



	for i in range(len(s)):

		D[s[i]].append(i+1)



	now=0

	cnt=0



	for i in t:

		if D[i]==[]:

			print((-1))

			exit(0)

		else:

			idx=bisect.bisect_right(D[i],now)

			try:

				now=D[i][idx]

			except:

				now=D[i][0]

				cnt+=1

	print((cnt*len(s)+now))

































if __name__ == "__main__":

	main()

from collections import defaultdict
import bisect

d = defaultdict(list)
s = eval(input())
t = eval(input())
ns = len(s)
nt = len(t)
for i in range(ns):
    d[s[i]].append(i)
for k, v in list(d.items()):
    d[k].append(ns)
# print(d)
ans = 0
cnt = -1
for i in range(nt):
    tt = d[t[i]]
    #  print(t[i],tt,ans,cnt)
    if tt == []:
        print((-1))
        exit(0)
    else:
        a = bisect.bisect_right(tt, cnt)
        #    print("ind",a)
        if tt[a] == ns:
            ans += ns + tt[0] - cnt
            cnt = tt[0]
        else:
            ans += tt[a] - cnt
            cnt = tt[a]
print(ans)

import sys

# input = sys.stdin.readline
input = sys.stdin.buffer.readline
# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np
from collections import defaultdict
import bisect


def main():
    s = input().rstrip().decode("utf-8")
    t = input().rstrip().decode("utf-8")
    D = defaultdict(list)
    for i in range(len(s)):
        D[s[i]].append(i + 1)
    now = 0
    cnt = 0
    for i in t:
        if D[i] == []:
            print((-1))
            exit(0)
        else:
            idx = bisect.bisect_right(D[i], now)
            try:
                now = D[i][idx]
            except:
                now = D[i][0]
                cnt += 1
    print((cnt * len(s) + now))


if __name__ == "__main__":
    main()

+import sys + +# input = sys.stdin.readline +input = sys.stdin.buffer.readline +# mod=10**9+7 +# rstrip().decode('utf-8') +# map(int,input().split()) +# import numpy as np -d = defaultdict(list) -s = eval(input()) -t = eval(input()) -ns = len(s) -nt = len(t) -for i in range(ns): -    d[s[i]].append(i) -for k, v in list(d.items()): -    d[k].append(ns) -# print(d) -ans = 0 -cnt = -1 -for i in range(nt): -    tt = d[t[i]] -    #  print(t[i],tt,ans,cnt) -    if tt == []: -        print((-1)) -        exit(0) -    else: -        a = bisect.bisect_right(tt, cnt) -        #    print("ind",a) -        if tt[a] == ns: -            ans += ns + tt[0] - cnt -            cnt = tt[0] + +def main(): +    s = input().rstrip().decode("utf-8") +    t = input().rstrip().decode("utf-8") +    D = defaultdict(list) +    for i in range(len(s)): +        D[s[i]].append(i + 1) +    now = 0 +    cnt = 0 +    for i in t: +        if D[i] == []: +            print((-1)) +            exit(0) -            ans += tt[a] - cnt -            cnt = tt[a] -print(ans) +            idx = bisect.bisect_right(D[i], now) +            try: +                now = D[i][idx] +            except: +                now = D[i][0] +                cnt += 1 +    print((cnt * len(s) + now)) + + +if __name__ == "__main__": +    main()