#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>		//UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>		//do setprecision
#include <ctime>
#include <complex>
#include <chrono>
#include<unordered_map>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define ALL(u) (u).begin(),(u).end()

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define LL long long
#define ULL unsigned LL
#define LD long double

typedef pair<int, int> PII;
typedef tuple<int, int, int, int, int> TIIIII;

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

void fast_io() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

const int INF = 1e9;
const int MR = 1e6 + 10;

string s[MR];
vector<PII> cost[4][MR];

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

vector<bool> done[4][MR];

int H, W;

bool ok(int x, int y, int k)
{
	return x + dx[k] >= 0 && x + dx[k] < H && y + dy[k] >= 0 && y + dy[k] < W;
}

int go(const PII &bg, const PII &nd, int K)
{
	priority_queue<TIIIII, vector<TIIIII>, greater<TIIIII> > Q;
	// cost jest zainicjalizowany odpowiednio

	// wstaw poczatkowe pole na 4 kierunki
	REP(k, 4)
	{
		cost[k][bg.first][bg.second] = MP(0, K);
		Q.push(MT(0, K, bg.first, bg.second, k));
	}

	while (!Q.empty())
	{
		auto akt = Q.top(); Q.pop();
		int h = get<2>(akt), w = get<3>(akt), dir = get<4>(akt);

		// czy pole przetworzone
		if (done[dir][h][w])
			continue;

		// przetwarzamy wlasciwy koszt
		done[dir][h][w] = 1;

		int stroke = get<0>(akt), ile = get<1>(akt);
		REP(k, 4)
		{
			int ndir = (dir + k) % 4;
			if (ok(h, w, ndir))
			{
				int nh = h + dx[ndir], nw = w + dy[ndir];

				// czye nie ma przeszkody
				if (s[nh][nw] == '@')
					continue;

				PII tmp;
				if (!k && ile < K)
					tmp = MP(stroke, ile + 1);
				else
					tmp = MP(stroke + 1, 1);

				if (cost[ndir][nh][nw] > tmp)
				{
					cost[ndir][nh][nw] = tmp;
					Q.push(MT(tmp.first, tmp.second, nh, nw, ndir));
				}
			}
		}
	}

	int res = INF;
	REP(k, 4)
		res = min(res, cost[k][nd.first][nd.second].first);

	if (res == INF)
		res = -1;
	return res;
}

int main()
{
	fast_io();
	int K;
	PII bg, nd;
	
	cin >> H >> W >> K;
	cin >> bg.first >> bg.second >> nd.first >> nd.second; bg.first--; bg.second--; nd.first--; nd.second--;

	REP(i, H)
	{
		cin >> s[i];
		REP(k, 4)
		{
			cost[k][i] = vector<PII>(W, MP(INF, K));
			done[k][i] = vector<bool>(W, false);
		}
	}

	printf("%d\n", go(bg, nd, K));

	return 0;
}

// FOR GNU C++ use the following pattern:
// Uncomment the code below and change your main into main2
// It does not build in MS C++
// But it does increase the stack size from 256 MB on CF and uses GNU C++

//#include <Processthreadsapi.h>
//#include <iostream>
//#include <Synchapi.h>
//#include <windows.h>
//#include <process.h>
//
//DWORD WINAPI MyThreadFunction(LPVOID lpParam) {
//    main2(nullptr);
//    return 0;
//}
//int main() {
//    auto h = CreateThread(nullptr, 1024 << 20, MyThreadFunction, nullptr, STACK_SIZE_PARAM_IS_A_RESERVATION, nullptr);
//    WaitForSingleObject(h, INFINITE);
//}

Measured memory_bytes: 251956