#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m=numeric_limits<T>::max()){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int H,W,K;
vector<string> field;

bool isReachable(Pi sij, Pi gij){
  vector<vector<bool>> seen(H, vector<bool>(W, false));
  seen[sij.first][sij.second] = true;
  queue<Pi> que;
  que.push(sij);
  while (!que.empty()){
    Pi v = que.front(); que.pop();
    for (int k=0; k<x4.size(); k++){
      int ni = v.first + x4[k];
      int nj = v.second+ y4[k];
      if (ni < 0 || ni >= H || nj < 0 || nj >= W) continue;
      if (field[ni][nj] == '@') continue;
      if (seen[ni][nj]) continue;
      seen[ni][nj] = true;
      que.push({ni,nj});
    }
  }
  return seen[gij.first][gij.second];
}

int main() {
  cin >>H >>W >>K;
  Pi sij; cin >>sij.first >>sij.second; sij.first--; sij.second--;
  Pi gij; cin >>gij.first >>gij.second; gij.first--; gij.second--;
  field.assign(H, ""); rep(i, H) cin >>field[i];
  if (!isReachable(sij, gij)){
    cout <<-1 <<endl; return 0;
  }
  vector<vector<vector<Pi>>> seen(H, vector<vector<Pi>>(W, vector<Pi>(4, {-1, 0})));
  // seen[i][j][k] := (i, j) についての情報。
  // k = {down, right, up, left}
  // k の方向に向かって来たとして、最小で何回水を書いてここまで来たか。 : first
  // そしてその最小回数で水をかいてきたとして、あと何マス水かきが残っていたか : second
  seen[sij.first][sij.second][0] = {0,0};
  seen[sij.first][sij.second][1] = {0,0};
  seen[sij.first][sij.second][2] = {0,0};
  seen[sij.first][sij.second][3] = {0,0};
  queue<pair<Pi, int>> que;
  que.push({sij, 0});
  que.push({sij, 1});
  que.push({sij, 2});
  que.push({sij, 3});
  while (!que.empty()){
    auto tmp = que.front(); que.pop();
    Pi ij; int dir; tie(ij, dir) = tmp;
    Pi now = seen[ij.first][ij.second][dir];
    for (int k=0; k<x4.size(); k++){
      int ni = ij.first  + x4[k];
      int nj = ij.second + y4[k];
      if (ni < 0 || ni >= H || nj < 0 || nj >= W) continue;
      if (field[ni][nj] == '@') continue;
      int times,sub;
      if (dir != k || now.second == 0){
        // 方向を変えるかブーストがキレたので回数は+1
        times = now.first+1;
        sub = K-1;
      }else{
        // 方向を買えないしブーストができる
        times = now.first;
        sub = now.second - 1; 
      }
      // こいつらをいれるかどうか
      Pi zantei = seen[ni][nj][k];
      if (zantei.first == -1 || times < zantei.first || (times == zantei.first && sub > zantei.second)){
        seen[ni][nj][k] = {times, sub};
        que.push(make_pair(Pi(ni, nj), k));
      }
    }
  }
  int res = INT_MAX;
  rep(k, 4){
    int buf = seen[gij.first][gij.second][k].first;
    if (buf == -1) continue;
    chmin(res, buf);
  }
  cout <<res <<endl;
}

Measured memory_bytes: 144884