import scala.collection.mutable.TreeSet

object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val h, w, k = sc.nextInt()
  val x1, y1, x2, y2 = sc.nextInt()-1
  val c = Array.fill(h)(sc.next()).map(_.map(_ == '@').toArray)
  val m = 1000000L

  def shortestPath(sx: Int, sy: Int): Array[Long] = {
    val sp = Array.fill(4 * h * w)(-m)
    val dir = Array((1,0), (0,1), (-1,0), (0,-1))
    val candidates = TreeSet[(Long, Int)]()
    sp(sx * w + sy) = 0
    candidates.add(0, sx * w + sy)

    while (candidates.nonEmpty) {
      val (ab, z1) = candidates.head
      candidates.remove((ab, z1))
      val d1 = z1 / (h * w)
      val x1 = (z1 % (h * w)) / w
      val y1 = z1 % w
      val a = ab / m
      val b = ab % m

      for (i <- -1 to 1) {
        val d2 = (d1+i+4) % 4
        val (x2, y2) = if (i == 0) {
          (x1 + dir(d2)._1, y1 + dir(d2)._2)
        } else {
          (x1, y1)
        }

        if (i != 0 || (0 <= x2 && x2 < h && 0 <= y2 && y2 < w && !c(x2)(y2))) {
          val costOld = sp(d2 * (h * w) + x2 * w + y2)
          val costNew = if (i == 0) {
            if (b == k-1) (a+1) * m else a * m + (b+1)
          } else {
            if (b == 0) a * m else (a+1) * m
          }

          if (costOld == -m) {
            sp(d2 * (h * w) + x2 * w + y2) = costNew
            candidates.add((costNew, d2 * (h * w) + x2 * w + y2))
          } else if (costNew < costOld) {
            sp(d2 * (h * w) + x2 * w + y2) = costNew
            candidates.remove((costNew, d2 * (h * w) + x2 * w + y2))
            candidates.add((costNew, d2 * (h * w) + x2 * w + y2))
          }
        }
      }
    }
    sp
  }

  val sp = shortestPath(x1, y1)
  val ans = (0 until 4).map{ d =>
    val ab = sp(d * (h * w) + x2 * w + y2)
    val a = ab / m
    val b = ab % m
    a + (if (b == 0) 0 else 1)
  }.min
  println(ans)
}
