def main():

    s = eval(input())

    t = eval(input())

    if not set(t).issubset(set(s)):

        return -1

    m = 0

    st = s

    for i in t:

        if i in st:

            j = st.index(i)

            m += j + 1

            st = st[j+1:]

        else:

            m += len(st)

            st = s

            j = st.index(i)

            st = st[j+1:]

            m += j + 1

    return m

print((main()))

import bisect

def main():

    s = eval(input())

    t = eval(input())

    if not set(t).issubset(set(s)):

        return -1

    d = {}

    n = len(s)

    for i, v in enumerate(s):

        if v in d:

            d[v].append(i)

            d[v].append(i + n)

        else:

            d[v] = [i, i+n]

    for i in d:

        d[i] = sorted(d[i])

    m = 0

    j = 0

    for i in t:

        ind = bisect.bisect_left(d[i], j)

        m += d[i][ind] - j + 1

        if d[i][ind] >= n:

            j = d[i][ind] - n + 1

        else:

            j = d[i][ind] + 1

    return m

print((main()))

def main():
    s = eval(input())
    t = eval(input())
    if not set(t).issubset(set(s)):
        return -1
    m = 0
    st = s
    for i in t:
        if i in st:
            j = st.index(i)
            m += j + 1
            st = st[j + 1 :]
        else:
            m += len(st)
            st = s
            j = st.index(i)
            st = st[j + 1 :]
            m += j + 1
    return m


print((main()))

import bisect


def main():
    s = eval(input())
    t = eval(input())
    if not set(t).issubset(set(s)):
        return -1
    d = {}
    n = len(s)
    for i, v in enumerate(s):
        if v in d:
            d[v].append(i)
            d[v].append(i + n)
        else:
            d[v] = [i, i + n]
    for i in d:
        d[i] = sorted(d[i])
    m = 0
    j = 0
    for i in t:
        ind = bisect.bisect_left(d[i], j)
        m += d[i][ind] - j + 1
        if d[i][ind] >= n:
            j = d[i][ind] - n + 1
        else:
            j = d[i][ind] + 1
    return m


print((main()))

+import bisect + + +    d = {} +    n = len(s) +    for i, v in enumerate(s): +        if v in d: +            d[v].append(i) +            d[v].append(i + n) +        else: +            d[v] = [i, i + n] +    for i in d: +        d[i] = sorted(d[i]) -    st = s +    j = 0 -        if i in st: -            j = st.index(i) -            m += j + 1 -            st = st[j + 1 :] +        ind = bisect.bisect_left(d[i], j) +        m += d[i][ind] - j + 1 +        if d[i][ind] >= n: +            j = d[i][ind] - n + 1 -            m += len(st) -            st = s -            j = st.index(i) -            st = st[j + 1 :] -            m += j + 1 +            j = d[i][ind] + 1