fun main(args : Array<String>) {
    val s = readLine()!!
    val t = readLine()!!

    val map = mutableMapOf<Char, MutableList<Long>>()

    s.forEachIndexed { index, c ->
        if (map.contains(c)) {
            map[c]!!.add(index.toLong())
        } else {
            map[c] = mutableListOf()
            map[c]!!.add(index.toLong())
        }
    }
    var ans = 0L
    var prev = -1L
   t.forEach {
       val indexes = map[it]
       if (indexes == null) {
           println(-1)
           return
       }
       val next = lowerBound(indexes, prev + 1)
       val nextIdx = if(next >= indexes.size) indexes.first() else indexes[next]
       ans += if(nextIdx > prev) nextIdx - prev else s.length - prev + nextIdx
       prev = nextIdx
   }
   println(ans)
}
fun lowerBound(sortedList: List<Long>, key: Long) : Int {
    var ng = - 1 // left
    var ok = sortedList.size  // right

    fun isOk(mid: Int) : Boolean {
        return sortedList.get(mid) >= key
    }

    while (Math.abs(ok - ng) > 1) {
        var mid = (ok + ng) / 2
        if (isOk(mid)) {
            ok = mid
        } else {
            ng = mid
        }
    }
    return ok
}
