from collections import defaultdict

from bisect import bisect_left





def main():

	s = eval(input())

	n = len(s)

	s = s + s

	t = eval(input())

	if set(t) - set(s):

		print((-1))

		exit()

	d = defaultdict(list)

	for i in range(2 * n):

		d[s[i]] += [i]

	cur = ncnt = 0



	for c in t:

		x = d[c][bisect_left(d[c], cur)]

		if x < n:

			cur = x + 1

		else:

			cur = x - n + 1

			ncnt += 1

	print((ncnt*n + cur))





if __name__ == "__main__":

	main()

import sys

from bisect import bisect_left as bi_l

from collections import defaultdict



def main():

    s, t = sys.stdin.read().split()

    if set(t) - set(s):

        print((-1))

        sys.exit()



    n = len(s)

    s *= 2

    c = defaultdict(list)

    for i in range(n * 2):

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



    i = 0

    l = 0 # left_most

    for ch in t:

        b = c[ch][bi_l(c[ch], l)]

        if b < n:

            l = b + 1

        else:

            l = b - n + 1

            i += n



    print((i+(l-1)+1)) # 最初が0のため



if __name__ == '__main__':

    main()
from collections import defaultdict
from bisect import bisect_left


def main():
    s = eval(input())
    n = len(s)
    s = s + s
    t = eval(input())
    if set(t) - set(s):
        print((-1))
        exit()
    d = defaultdict(list)
    for i in range(2 * n):
        d[s[i]] += [i]
    cur = ncnt = 0
    for c in t:
        x = d[c][bisect_left(d[c], cur)]
        if x < n:
            cur = x + 1
        else:
            cur = x - n + 1
            ncnt += 1
    print((ncnt * n + cur))


if __name__ == "__main__":
    main()

import sys
from bisect import bisect_left as bi_l
from collections import defaultdict


def main():
    s, t = sys.stdin.read().split()
    if set(t) - set(s):
        print((-1))
        sys.exit()
    n = len(s)
    s *= 2
    c = defaultdict(list)
    for i in range(n * 2):
        c[s[i]].append(i)
    i = 0
    l = 0  # left_most
    for ch in t:
        b = c[ch][bi_l(c[ch], l)]
        if b < n:
            l = b + 1
        else:
            l = b - n + 1
            i += n
    print((i + (l - 1) + 1))  # 最初が0のため


if __name__ == "__main__":
    main()

+import sys +from bisect import bisect_left as bi_l -from bisect import bisect_left -    s = eval(input()) -    n = len(s) -    s = s + s -    t = eval(input()) +    s, t = sys.stdin.read().split() -        exit() -    d = defaultdict(list) -    for i in range(2 * n): -        d[s[i]] += [i] -    cur = ncnt = 0 -    for c in t: -        x = d[c][bisect_left(d[c], cur)] -        if x < n: -            cur = x + 1 +        sys.exit() +    n = len(s) +    s *= 2 +    c = defaultdict(list) +    for i in range(n * 2): +        c[s[i]].append(i) +    i = 0 +    l = 0  # left_most +    for ch in t: +        b = c[ch][bi_l(c[ch], l)] +        if b < n: +            l = b + 1 -            cur = x - n + 1 -            ncnt += 1 -    print((ncnt * n + cur)) +            l = b - n + 1 +            i += n +    print((i + (l - 1) + 1))  # 最初が0のため