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))
from bisect import bisect_left

from collections import defaultdict as dd



def main():



  s=eval(input())

  t=eval(input())

  n=len(s)



  dic=dd(list)

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

    dic[i].append(idx)



  ans,p=0,-1

  for i in t:

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

      print((-1))

      exit()

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

    if p>=n:

      p-=n

      ans+=n



  print((ans+p+1))



if __name__=='__main__':

  main()
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))

from bisect import bisect_left
from collections import defaultdict as dd


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


if __name__ == "__main__":
    main()

-import bisect +from bisect import bisect_left +from collections import defaultdict as dd -s = eval(input()) -t = eval(input()) -n = len(s) -dic = {} -for idx, i in enumerate(s * 2): -    if i in list(dic.keys()): + +def main(): +    s = eval(input()) +    t = eval(input()) +    n = len(s) +    dic = dd(list) +    for idx, i in enumerate(s * 2): -    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)) +    ans, p = 0, -1 +    for i in t: +        if i not in list(dic.keys()): +            print((-1)) +            exit() +        p = dic[i][bisect_left(dic[i], p + 1)] +        if p >= n: +            p -= n +            ans += n +    print((ans + p + 1)) + + +if __name__ == "__main__": +    main()