#include <bits/stdc++.h>



using namespace std;

const int Nmax = 50000 + 10;

int i , n , ans;
int p[Nmax] , aib[Nmax];
int nxt[Nmax] , last[30] , crt[30];

char a[Nmax] , b[Nmax];

int aibQuery(int i)
{
    int ret = 0;
    for ( ; i ; i -= (i&(-i)))
        ret += aib[i];
    return ret;
}

void aibUpdate(int i)
{
    for ( ; i <= n; i += (i&(-i)))
        aib[i]++;
}

int main()
{
    freopen("swap.in","r",stdin);
    freopen("swap.out","w",stdout);

    fgets(a, 50001, stdin); fgets(b, 50001, stdin); n = strlen(a+1);

    for (i = 1; i <= n; ++i)
    {
        if (!last[b[i]-'a']) crt[b[i]-'a'] = i;
        nxt[last[b[i]-'a']] = i;
        last[b[i]-'a'] = i;
    }

    for (i = 1; i <= n; ++i)
    {
        if (!crt[a[i]-'a'])
        {
            printf("-1\n");
            return 0;
        }
        p[i] = crt[a[i]-'a'];
        crt[a[i]-'a'] = nxt[crt[a[i]-'a']];
    }

    for (i = n ; i ; --i)
    {
        ans += aibQuery(p[i]);
        aibUpdate(p[i]);
    }

    printf("%d\n", ans);

    return 0;
}