#include<bits/stdc++.h>
#define up(j,k,i) for(ll i=j;i<k;i++)
#define down(j,k,i) for(ll i=j;i>k;i--)
#define M 1000000007
#define pp(n) printf("%lld\n",ll(n))
#define ps(n) printf("%lld ",ll(n))
#define pd(x,y) printf("%lld %lld\n",ll(x),ll(y))
#define is(n) scanf("%lld",&n)
#define inf 1e15
#define id(n,m) scanf("%lld%lld",&n,&m)
#define it(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define ss(s) scanf("%s",s)
#define cool 0
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pll pair<ll,ll> 
#define db cout<<"######\n"
#define null(a) memset(a,0,sizeof(a))
#define neg(a) memset(a,255,sizeof(a))
typedef long double ld;
typedef long long int ll;
using namespace std;
ll i,j,k,z,t,n,m,sum,ans,x,y,maxm=0,minm=inf; bool flag;
ll dist[805][805];
vector<pll> reach;
char a[805][805];
inline ll ceil(ll x,ll y)
{
if(x%y) return x/y+1;
else return x/y;
}
bool check(ll x, ll y)
{
if(x<1||x>n||y<1||y>m)
return false;
else
if(a[x][y]=='#')
return false;
else return true;
}
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
void bfs(ll x,ll y)
{
	dist[x][y]=0;
	
	priority_queue<pair<ll,pll>,vector<pair<ll,pll>>, greater<pair<ll,pll> >> Q;
	
	Q.push({0,{x,y}});
	
	while(!Q.empty())
	{
		auto c=Q.top(); Q.pop();
		
		z=c.F; x=c.S.F; y=c.S.S;
		
		if(z>k)
		continue;
		else
		reach.pb({x,y});
		
		up(0,4,i)
		if(check(x+dx[i],y+dy[i]))
		if(dist[x+dx[i]][y+dy[i]]>z+1)
		dist[x+dx[i]][y+dy[i]]=z+1,Q.push({z+1,{x+dx[i],y+dy[i]}});
		
	}
}
int main()
{
	it(n,m,k);
	
	up(1,n+1,i)
	up(1,m+1,j)
	{
		
		cin>>a[i][j];
		
		if(a[i][j]=='')
		x=i,y=j;
		
		dist[i][j]=inf;
	}
	
	if(x==1 or y==1)
	{
		pp(0);
		return 0;
	}
	
	bfs(x,y);
	
	ans=inf;
	
	for(auto c:reach)
	{
		ans=min(ans,min(min(ceil(n-c.F,k),ceil(c.F-1,k)),min(ceil(m-c.S,k),ceil(c.S-1,k)))+1);
	}
	
	pp(ans);	
}	
