//////////////////////////
//////////////////////////
////Please give me AC!////
////Please give me AC!////
//////////////////////////
//////////////////////////
func readInts() -> [Int]{
    return readLine()!.split(separator: " ").map{Int($0)!};
}
let R1 = readInts();
let R2 = readInts();
let H = Int(R1[0]), W = Int(R1[1]), K = Int(R1[2]), x1 = Int(R2[0]), y1 = Int(R2[1]), x2 = Int(R2[2]), y2 = Int(R2[3]);
var pond: Array<Character> = Array(repeating: "0", count: H * W);
for i in 0 ..< H {
    let R = readLine()!
    let S = String(R);
    var  k = 0;
    for j in S {
        pond[i * W + k] = j;
        k += 1;
    }
}
var vec:[[Int]] = []
for i in  0 ..< H*W {
    vec.append([]);
    if(pond[i] == "@") {
        continue;
    }
    if(i >= W) {
        if(pond[i - W] != "@") {
            vec[i].append(i - W);
        }
    }
    if(i < W * (H - 1)) {
        if(pond[i + W] != "@") {
            vec[i].append(i + W);
        }
    }
    if(i % W != 0) {
        if(pond[i - 1] != "@") {
            vec[i].append(i - 1);
        }
    }
    if(i % W != W - 1) {
        if(pond[i + 1] != "@") {
            vec[i].append(i + 1);
        }
    }
}
var dist:[[Int]] = [];
for i in 0 ..< H*W {
    dist.append([]);
    for _ in 0 ..< 4 {
        dist[i].append(10000000);
    }
}
var que:[Int] = [];
dist[W * (x1 - 1) + y1 - 1][0] = 0;
dist[W * (x1 - 1) + y1 - 1][1] = 0;
dist[W * (x1 - 1) + y1 - 1][2] = 0;
dist[W * (x1 - 1) + y1 - 1][3] = 0;
que.append(W * (x1 - 1) + y1 - 1);
while(que.count != 0) {
    let v = Int(que[0]);
    que.removeFirst();
    for i in 0 ..< vec[v].count {
        let nv = vec[v][i];
        var n0 = Int(), n1 = Int(), n2 = Int(), n3 = Int();
        if(nv - v == 1) {
            n0 = dist[v][0] + 1;
            if(dist[nv][0] > n0) {
                dist[nv][0] = n0;
                dist[nv][1] = min(dist[nv][1], n0 - n0 % K + K * ((n0 % K + K - 1) / K));
                dist[nv][2] = min(dist[nv][2], n0 - n0 % K + K * ((n0 % K + K - 1) / K));
                dist[nv][3] = min(dist[nv][3], n0 - n0 % K + K * ((n0 % K + K - 1) / K));
                que.append(nv);
            }
        }
        if(nv-v == -W) {
            n1 = dist[v][1] + 1;
            if(dist[nv][1] > n1) {
                dist[nv][1] = n1;
                dist[nv][0] = min(dist[nv][0], n1 - n1 % K + K * ((n1 % K + K - 1) / K));
                dist[nv][2] = min(dist[nv][2], n1 - n1 % K + K * ((n1 % K + K - 1) / K));
                dist[nv][3] = min(dist[nv][3], n1 - n1 % K + K * ((n1 % K + K - 1) / K));
                que.append(nv);
            }
        }
        if(nv-v == -1) {
            n2 = dist[v][2] + 1;
            if(dist[nv][2] > n2) {
                dist[nv][2] = n2;
                dist[nv][0] = min(dist[nv][0], n2 - n2 % K + K * ((n2 % K + K - 1) / K));
                dist[nv][1] = min(dist[nv][1], n2 - n2 % K + K * ((n2 % K + K - 1) / K));
                dist[nv][3] = min(dist[nv][3], n2 - n2 % K + K * ((n2 % K + K - 1) / K));
                que.append(nv);
                
            }
        }
        if(nv-v == W) {
            n3=dist[v][3]+1;
            if(dist[nv][3]>n3) {
                dist[nv][3] = n3;
                dist[nv][0] = min(dist[nv][0], n3 - n3 % K + K * ((n3 % K + K - 1) / K));
                dist[nv][1] = min(dist[nv][1], n3 - n3 % K + K * ((n3 % K + K - 1) / K));
                dist[nv][2] = min(dist[nv][2], n3 - n3 % K + K * ((n3 % K + K - 1) / K));
                que.append(nv);
            }
        }
    }
}
let ans = min(min(dist[W * (x2 - 1) + y2 - 1][0], dist[W * (x2 - 1) + y2 - 1][1]), min(dist[W * (x2 - 1) + y2 - 1][2], dist[W * (x2 - 1) + y2 - 1][3]));
if(ans == 10000000){
    print(-1);
}
else{
    print(ans / K + (ans % K + K - 1) / K);
}