#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

// #define DEBUG_MODE
#ifdef DEBUG_MODE
#define dump(x) cout << #x << " : " << x << " "
#define dumpL(x) cout << #x << " : " << x << '\n'
#define LINE cout << "line : " << __LINE__ << " "
#define LINEL cout << "line : " << __LINE__ << '\n'
#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << " "
#define dumpVL(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl
#define STOP assert(false)
#else
#define dump(x) 
#define dumpL(x) 
#define LINE 
#define LINEL 
#define dumpV(v) 
#define dumpVL(v) 
#define STOP assert(false)
#endif
#define mp make_pair
 
namespace std {
template<class S, class T>
ostream &operator <<(ostream& out, const pair<S, T>& a) {
    out << '(' << a.fi << ", " << a.se << ')';
    return out;
}
}

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w, K;
    cin >> h >> w >> K;
    int sy, sx, gy, gx;
    cin >> sy >> sx >> gy >> gx;
    --sy; --sx;
    --gy; --gx;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    using P = pair<int, int>;
    const int INF = 1e9;
    vector<vector<vector<P>>> dp(h);
    rep(i, h) {
        dp[i].resize(w);
        rep(j, w) dp[i][j].resize(4, P(INF, INF));
    }
    using T = tuple<pii, int, int, int>;
    priority_queue<T, vector<T>, greater<T> > q;
    rep(k, 4) {
        dp[sy][sx][k] = {0, 0};
        q.emplace(dp[sy][sx][k], sy, sx, k);
    }
    while(!q.empty()) {
        auto t = q.top();
        q.pop();
        auto& [p, y, x, d] = t;
        if(p != dp[y][x][d]) continue;
        dump(p);dump(y);dump(x);dumpL(d);

        rep(k, 4) {
            int nx = x + dx[k];
            int ny = y + dy[k];
            if(nx < 0 || ny < 0 || nx >= w || ny >= h || s[ny][nx] == '@') continue;
            if(k == d) {
                pii nxt = p;
                if(nxt.se == 0) {
                    nxt.fi++;
                    nxt.se = -K+1;
                }
                else {
                    nxt.se++;
                }
                if(nxt < dp[ny][nx][k]) {
                    dp[ny][nx][k] = nxt;
                    q.emplace(nxt, ny, nx, k);
                }
            }
            else {
                pii nxt;
                nxt.fi = p.fi+1;
                nxt.se = -K+1;
                if(nxt < dp[ny][nx][k]) {
                    dp[ny][nx][k] = nxt;
                    q.emplace(nxt, ny, nx, k);
                }
            }
        }
    }

    int ans = INF;
    rep(k, 4) chmin(ans, dp[gy][gx][k].fi);
    if(ans == INF) ans = -1;
    cout << ans << '\n';

    // rep(i, h) {
    //     rep(j, w) {
    //         cout << "(";
    //         rep(k, 4) cout <<"["<<(dp[i][j][k].fi == INF ? -1:dp[i][j][k].fi) << "," <<  (dp[i][j][k].se == INF ? 0:dp[i][j][k].se) << "] ";
    //         cout << ") ";
    //     }
    //     cout << '\n';
    // }
    // cout << '\n';
    return 0;
}

Measured memory_bytes: 80084