import scala.annotation.tailrec
import scala.collection.mutable

object Main extends App{
  import scala.io.StdIn._
  solve()
  @tailrec def solve(): Unit = {
    val Array(h, w) = readLine.trim.split(' ').map(_.toInt)
    if (h == 0) return
    val map = mutable.Map[Char, Coordinate]()
    for (height ← 0 until h){
      val line = readLine.trim
      for (width ← 0 until w if line(width) != '_') {
        map(line(width)) = Coordinate(height, width)
      }
    }
    val statement = readLine.trim
    var current = Coordinate(0, 0)
    var sum = 0
    for (s ← statement) {
      val next = map(s)
      sum += current.manhattanDistance(next) + 1
      current = next
    }
    println(sum)
    solve()
  }
  case class Coordinate(x: Int, y: Int) {
    def manhattanDistance(that: Coordinate): Int = math.abs(x - that.x) + math.abs(y - that.y)
  }
}
