function Main(input) {
 
    var s = input.split('\n')[0];
    var str = s;
    var t = input.split('\n')[1];

    var set = new Set(t.split(''));

    for (var x of set) {
        if (s.indexOf(x) === -1) {
            console.log(-1);
            return;
        }
    }

    var ans = 0;
    var f = true;
    var first = 0;
    while (1) {
        var tmp = s.length;
        for (var i = 0; i < t.length; i++){
            var a = s.substr(0, tmp).lastIndexOf(t[t.length - 1 - i]);
            if (tmp < a || a === -1) {
                f = false;
                break;
            }
            if (i === 0) first = a;
            tmp = a;
        }
        if (f) {
            ans = tmp;
            break;
        }
        s = s + str;
        f = true;
    }

    console.log(first+1);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));