#include <bits/stdc++.h>
using namespace std;
int k, n, dx[5] = {1, 0, -1, 0, 0}, dy[5] = {0, 1, 0, -1, 0};
struct node
{
int x, y;
int step;
};
char a[305][305];
queue < node > q;
bool check(int x, int y, int r)
{
for(int i = x - (r / 2); i <= x + (r / 2); i++) for(int j = y - (r / 2); j <= y + (r / 2); j++) if(i > n || j > n || i < 1 || j < 1 || a[i][j] == '*') return false;
return true;
}
int main()
{
cin >> n >> k;
for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) cin >> a[i][j];
q.push({3, 3, 0});
int tx, ty;
while(!q.empty())
{
node now = q.front();
q.pop();
if(now.x == n - 2 && now.y == n - 2)
{
cout << now.step;
exit(0);
}
for(int i = 0; i < 5; i++)
{
tx = now.x + dx[i];
ty = now.y + dy[i];
int tr;
if(now.step < k)tr = 5;
else if(now.step < 2 * k)tr = 3;
else tr = 1;
if(tx >= 1 && tx <= n && ty >= 1 && ty <= n && a[tx][ty] == '+' && check(tx, ty, tr)) q.push({tx, ty, now.step + 1});
}
}
return 0;
}