#include <bits/stdc++.h>
using namespace std;

#define int ll

#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end() 
#define sz(v) (int)((v).size())
#define fs first
#define sd second

typedef long long ll;

typedef pair < int, int > pi;
typedef pair < pi, int > ppi;

typedef vector < int > vi;
typedef vector < vector < int > > vvi;
typedef vector < pi > vpi;
typedef vector < vpi > vvpi;
typedef vector < ppi > vppi;

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}

void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifdef LOCAL
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

double get_time() {
	return 1.0 * clock() / CLOCKS_PER_SEC;
}

const int INF = 1E15 + 100;
int h, w, k;
int sx, sy, ex, ey;
vvi grid;

struct Node {
	int x, y, t;
	int dist;
	Node(int _x, int _y, int _t, int _dist) {
		x = _x;
		y = _y;
		t = _t;
		dist = _dist;
	}
	bool operator < (const Node& n) const {
		return tie(dist, x, y, t) < tie(n.dist, n.x, n.y, n.t);
	}
};

void solve() {
	int dx[] = {1, -1, 0, 0};
	int dy[] = {0, 0, 1, -1};
	int d[h + 2][w + 2][4];
	for(int i = 0; i < h + 2; i++) {
		for(int j = 0; j < w + 2; j++) {
			for(int t = 0; t < 4; t++) {
				d[i][j][t] = INF;
			}
		}
	}
	d[sx][sy][0] = k;
	set<Node> s;
	s.insert(Node(sx, sy, 0, k));
	while(!s.empty()) {
		int dist = (*s.begin()).dist, x = (*s.begin()).x, y = (*s.begin()).y, t = (*s.begin()).t;
		s.erase(s.begin());
		// debug(x, y, t, dist);
		// for(int dx = -1; dx <= 1; dx++) {
		// 	for(int dy = -1; dy <= 1; dy++) {
		// 		if(dx * dx + dy * dy != 1)
		// 			continue;
		// 		int nx = x + dx, ny = y + dy;
		// 		if(nx > h || ny > w || nx < 1 || ny < 1)
		// 			continue;
		// 		if(grid[nx][ny])
		// 			continue;
		// 		if(d[nx][ny][t] > dist + 1) {
		// 			d[nx][ny][t] = dist + 1;
		// 			s.insert(Node(nx, ny, t, d[nx][ny][t]));
		// 		}
		// 	}
		// }
		int nx = x + dx[t], ny = y + dy[t];
		if(!(nx > h || ny > w || nx < 1 || ny < 1) && !grid[nx][ny]) {
			if(d[nx][ny][t] > dist + 1) {
				d[nx][ny][t] = dist + 1;
				s.insert(Node(nx, ny, t, d[nx][ny][t]));
			}
		}
		for(int i = 0; i < 3; i++) {
			int nt = (t + i) % 4;
			if(d[x][y][t] % k > 0) {
				if(d[x][y][nt] > k * (d[x][y][t]/k) + k) {
					d[x][y][nt] = k * (d[x][y][t]/k) + k;
					s.insert(Node(x, y, nt, d[x][y][nt]));
				}
			}
			else {
				if(d[x][y][nt] > d[x][y][t]) {
					d[x][y][nt] = d[x][y][t];
					// debug(true);
					s.insert(Node(x, y, nt, d[x][y][nt]));
				}
			}
		}
	}
	int best = INF;
	for(int i = 0; i < 4; i++)
		best = min(best, d[ex][ey][i]);
	if(best == INF)
		cout << -1 << '\n';
	else
		cout << (best - 1)/k << '\n'; 
}

int32_t main() {
	fast();
	cin >> h >> w >> k >> sx >> sy >> ex >> ey;
	grid.resize(h + 2, vi(w + 2));
	for(int i = 1; i <= h; i++) {
		for(int j = 1; j <= w; j++) {
			char ch;
			cin >> ch;
			grid[i][j] = (ch == '@');
		}
	}
	solve();
}

/*
1 2 1
1 1
1 2
. .
*/

Measured memory_bytes: 120532