module IntMap = Map.Make (struct
  type t = int
  let compare = compare
end)

let () = Scanf.scanf "%d %d %d\n%d %d %d %d\n" @@ fun h w k x1 y1 x2 y2 ->
  let css = Array.init h @@ fun _ -> Scanf.scanf "%s\n" Fun.id in
  let d =
    Array.init h @@ fun _ ->
      Array.init w @@ fun _ ->
        Array.init 4 @@ fun _ -> max_int in
  let dx = [| 1; 0; -1; 0 |] in
  let dy = [| 0; 1; 0; -1 |] in
  d.(x1 - 1).(y1 - 1).(0) <- 0;
  let rec dijkstra q =
    match IntMap.min_binding_opt q with
    | None -> ()
    | Some (c, us) ->
        dijkstra @@
        List.fold_left (fun q (i, j, dir) ->
          if d.(i).(j).(dir) < c
          then q
          else
            List.fold_left (fun q (i, j, dir', d') ->
              if i < 0 || h <= i || j < 0 || w <= j || css.(i).[j] = '@' || d.(i).(j).(dir') <= d'
              then q
              else begin
                d.(i).(j).(dir') <- min d' d.(i).(j).(dir');
                IntMap.update d' (fun vs -> Some ((i, j, dir') :: Option.value ~default:[] vs)) q 
              end) q
            [(i + dx.(dir), j + dy.(dir), dir, c + 1); (i, j, (dir + 1) mod 4, c + k - 1 - (c + k - 1) mod k)]) (IntMap.remove c q) us in
  dijkstra (IntMap.singleton 0 [(x1 - 1, y1 - 1, 0)]);
  Printf.printf "%d\n" @@
  (fun x -> if max_int <= x then -1 else (x + k - 1) / k) @@
  Array.fold_left min max_int d.(x2 - 1).(y2 - 1)
