// Arup Guha
// 11/11/2017
// Solution to 2017 SER D1 Problem: Jumping Haybales

import java.util.*;

public class haybales {

	final public static int MAX = 1000000;

	public static char[][] grid;
	public static int n;
	public static int k;

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		n = stdin.nextInt();
		k = stdin.nextInt();
		grid = new char[n][];

		// Read in the grid.
		for (int i=0; i<n; i++)
			grid[i] = stdin.next().toCharArray();

		System.out.println(bfs());
	}

	public static int bfs() {

		LinkedList<Integer> q = new LinkedList<Integer>();
		int[][] res = new int[n][n];
		for (int i=0; i<n; i++) Arrays.fill(res[i], MAX);
		res[0][0] = 0;
		q.offer(0);

		// Stores the smallest column in each row we need to check.
		int[] minRowStart = new int[n];

		// Stores the smallest row in each col we need to check.
		int[] minColStart = new int[n];

		// Run our bfs.
		while (q.size() > 0) {

			// Get next item.
			int cur = q.poll();
			int x = cur/n;
			int y = cur%n;

			// Got to end.
			if (x == n-1 && y == n-1) return res[x][y];

			// Go right.
			for (int col=Math.max(y+1, minRowStart[x]); col<=y+k && col<n; col++) {

				// No need to go further.
				if (res[x][col] < res[x][y]) break;

				// Can't jump here.
				if (grid[x][col] == '#') continue;

				// Stores this distance and add to queue.
				if (res[x][col] == MAX) {
					res[x][col] = 1 + res[x][y];
					q.offer(n*x + col);
					minRowStart[x] = col+1;
				}
			}

			// Go down.
			for (int row=Math.max(x+1, minColStart[y]); row<=x+k && row<n; row++) {

				// No need to go further.
				if (res[row][y] < res[x][y]) break;

				// Can't jump here.
				if (grid[row][y] == '#') continue;

				// Stores this distance and add to queue.
				if (res[row][y] == MAX) {
					res[row][y] = 1 + res[x][y];
					q.offer(n*row + y);
					minColStart[y] = row+1;
				}
			}
		}

		// If we get here, we never got to the end.
		return -1;
	}
}