You have a grid with n rows and n columns. Each cell is either empty (denoted by '.') or blocked (denoted by 'X').Two empty cells are directly connected if they share a side. Two cells (r1, c1) (located in the row r1 and column c1) and (r2, c2) are connected if there exists a sequence of empty cells that starts with (r1, c1), finishes with (r2, c2), and any two consecutive cells in this sequence are directly connected. A connected component is a set of empty cells such that any two cells in the component are connected, and there is no cell in this set that is connected to some cell not in this set.Your friend Limak is a big grizzly bear. He is able to destroy any obstacles in some range. More precisely, you can choose a square of size k × k in the grid and Limak will transform all blocked cells there to empty ones. However, you can ask Limak to help only once.The chosen square must be completely inside the grid. It's possible that Limak won't change anything because all cells are empty anyway.You like big connected components. After Limak helps you, what is the maximum possible size of the biggest connected component in the grid?

The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 500) — the size of the grid and Limak's range, respectively. Each of the next n lines contains a string with n characters, denoting the i-th row of the grid. Each character is '.' or 'X', denoting an empty cell or a blocked one, respectively.

Print the maximum possible size (the number of cells) of the biggest connected component, after using Limak's help.

NoteIn the first sample, you can choose a square of size 2 × 2. It's optimal to choose a square in the red frame on the left drawing below. Then, you will get a connected component with 10 cells, marked blue in the right drawing.

import java.io.*;
import java.util.*;

public class Main {

	public static int mod = 1000000007,n,max_ans,cc_count,cc[];
	public static boolean visited[][],grid[][];
	//public static ArrayList<ArrayList<Node>> cc_list;
	//public static ArrayList<Node> cc;
	public static int size[];
	public static int dx[]={1,0,-1,0};
	public static int dy[]={0,1,0,-1};
//	public static HashMap<Integer,Integer> map;
	public static void main(String[] args)throws IOException {
		// TODO Auto-generated method stub
		InputStream input = System.in;
		InputReader in = new InputReader(input);

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// map = new HashMap<Integer,Integer>();
		 n = in.nextInt();
		int k = in.nextInt();
		max_ans = Integer.MIN_VALUE;
		 grid = new boolean[n][n];
		 size = new int[250001];
		 cc = new int[250001];
		 int contains[] = new int[250001];
		 int contain=0;
	//	cc_list = new ArrayList<ArrayList<Node>>();
		for(int i=0;i<n;i++)
		{
			String s = in.next();

			for(int j=0;j<n;j++)
				if(s.charAt(j)=='.')
					grid[i][j] = true;

		}

		visited= new boolean[n][n];
		 cc_count=0;
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				if(!visited[i][j] && grid[i][j])
					{
				//	cc = new ArrayList<Node>();
					dfs(i,j);
				//	cc_list.add(cc);
					cc_count++;
					}

	//	for(int i=0;i<4;i++)
		//	System.out.println(size[i]);

		for(int i=0;i<k;i++)
			for(int j=0;j<k;j++)
			{

				if(!grid[i][j])
				continue;

				size[cc[i*n+j]]--;

			}
//
//	Set<Integer> set = new HashSet<Integer>();

		for(int i=0;i<=n-k;i++)
			{for(int j=0;j<=n-k;j++)
			{//System.out.println(i+" "+j);
				contain++;
				int curr_ans = k*k;

				//	for(int ii=0;ii<4;ii++)
				//		System.out.print(size[ii]+" ");
				//	System.out.println();
				//set.clear();

				if(i!=0)
				{
					for(int y=j;y<j+k;y++)
						if(grid[i-1][y])
						{
							int ss = cc[n*(i-1)+y];
							if(contain!=contains[ss])
							{
								curr_ans += size[ss];
								contains[ss]=contain;
							}
						}

				}
				if(i!=n-k)
				{

					for(int y=j;y<j+k;y++)
						if(grid[i+k][y])
						{
							int ss = cc[n*(i+k)+y];
							if(contain!=contains[ss])
							{
								curr_ans += size[ss];
								contains[ss]=contain;
							}
						}

				}

				if(j!=0)
				{
					for(int x=i;x<i+k;x++)
						if(grid[x][j-1])
						{
							int ss = cc[(n*(x)+j-1)];
							if(contain!=contains[ss])
							{
								curr_ans += size[ss];
								contains[ss]=contain;
							}
						}

				}
				if(j!=n-k)
				{
					for(int x=i;x<i+k;x++)
						if(grid[x][j+k])
						{
							int ss = cc[(n*(x)+j+k)];
							if(contain!=contains[ss])
							{
								curr_ans += size[ss];
								contains[ss]=contain;
							}
						}

				}

			/*	Iterator<Integer> ir = set.iterator();

				while(ir.hasNext())
				{	int aa = ir.next();
			//	System.out.println(aa+" s "+size[aa]);
					curr_ans += size[aa];

				} */

				max_ans = Math.max(max_ans, curr_ans);
			//	System.out.println(curr_ans);

			if(j==n-k)
			{
				for(int x=i;x<i+k;x++)
					for(int y=j;y<j+k;y++)
						if(grid[x][y])
							size[cc[(x*n+y)]]++;

				//System.out.println("x");

			}
			else
			{
				for(int x=i;x<i+k;x++)
					{if(grid[x][j])
						size[cc[(x*n+j)]]++;
					if(grid[x][j+k])
						size[cc[(x*n+j+k)]]--;
					}

			}

		//	System.out.println(i+" i");
		//	for(int ii=0;ii<4;ii++)
		//		System.out.print(size[ii]+" ");
		//	System.out.println();

			}

			if(i!=n-k)
			for(int x=i+1;x<i+k+1;x++)
				for(int y=0;y<k;y++)
					if(grid[x][y])
						size[cc[x*n+y]]--;
			//System.out.println(i+" i");

	}

		System.out.println(max_ans);

	}

	public static void dfs(int x,int y)
	{

		visited[x][y]=true;

		//cc.add(new Node(x,y));
	//	map.put(x*n + y, cc_count);
		cc[x*n+y]=cc_count;
		size[cc_count]++;
		//System.out.println(x+" "+y);
		int x1=0,y1=0;

		for(int i=0;i<4;i++)
		{//System.out.println();
			x1=x+dx[i];
			y1 = y+ dy[i];

			if(x1<0 || x1>=n || y1<0 || y1 >= n)
				continue;

			if(grid[x1][y1] && !visited[x1][y1])
				dfs(x1,y1);

		}

	}

	static class Node{

		int x,y;

		Node(int x,int y)
		{
			this.x=x;this.y=y;
		}
	}

	static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while  (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

import java.io.*;
import java.util.*;

public class Main {

	public static int mod = 1000000007,n,max_ans,cc_count,cc[];
	public static boolean visited[][],grid[][];

	public static int size[];
	public static int dx[]={1,0,-1,0};
	public static int dy[]={0,1,0,-1};

	public static void main(String[] args)throws IOException {
		// TODO Auto-generated method stub
		InputStream input = System.in;
		InputReader in = new InputReader(input);

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		 n = in.nextInt();
		int k = in.nextInt();
		max_ans = Integer.MIN_VALUE;
		 grid = new boolean[n][n];
		 size = new int[250001];
		 cc = new int[250001];
		 int contains[] = new int[250001];
		 int contain=0;

		for(int i=0;i<n;i++)
		{
			String s = in.next();

			for(int j=0;j<n;j++)
				if(s.charAt(j)=='.')
					grid[i][j] = true;

		}

		visited= new boolean[n][n];
		 cc_count=0;
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				if(!visited[i][j] && grid[i][j])
					{

					dfs(i,j);

					cc_count++;
					}

		for(int i=0;i<k;i++)
			for(int j=0;j<k;j++)
			{

				if(!grid[i][j])
				continue;

				size[cc[i*n+j]]--;

			}

		for(int i=0;i<=n-k;i++)
			{for(int j=0;j<=n-k;j++)
			{
				contain++;
				int curr_ans = k*k;

				if(i!=0)
				{
					for(int y=j;y<j+k;y++)
						if(grid[i-1][y])
						{
							int ss = cc[n*(i-1)+y];
							if(contain!=contains[ss])
							{
								curr_ans += size[ss];
								contains[ss]=contain;
							}
						}

				}
				if(i!=n-k)
				{

					for(int y=j;y<j+k;y++)
						if(grid[i+k][y])
						{
							int ss = cc[n*(i+k)+y];
							if(contain!=contains[ss])
							{
								curr_ans += size[ss];
								contains[ss]=contain;
							}
						}

				}

				if(j!=0)
				{
					for(int x=i;x<i+k;x++)
						if(grid[x][j-1])
						{
							int ss = cc[(n*(x)+j-1)];
							if(contain!=contains[ss])
							{
								curr_ans += size[ss];
								contains[ss]=contain;
							}
						}

				}
				if(j!=n-k)
				{
					for(int x=i;x<i+k;x++)
						if(grid[x][j+k])
						{
							int ss = cc[(n*(x)+j+k)];
							if(contain!=contains[ss])
							{
								curr_ans += size[ss];
								contains[ss]=contain;
							}
						}

				}

				max_ans = Math.max(max_ans, curr_ans);

			if(j==n-k)
			{
				for(int x=i;x<i+k;x++)
					for(int y=j;y<j+k;y++)
						if(grid[x][y])
							size[cc[(x*n+y)]]++;

			}
			else
			{
				for(int x=i;x<i+k;x++)
					{if(grid[x][j])
						size[cc[(x*n+j)]]++;
					if(grid[x][j+k])
						size[cc[(x*n+j+k)]]--;
					}

			}

			}

			if(i!=n-k)
			for(int x=i+1;x<i+k+1;x++)
				for(int y=0;y<k;y++)
					if(grid[x][y])
						size[cc[x*n+y]]--;

	}

		System.out.println(max_ans);

	}

	public static void dfs(int x,int y)
	{

		visited[x][y]=true;

		cc[x*n+y]=cc_count;
		size[cc_count]++;

		int x1=0,y1=0;

		for(int i=0;i<4;i++)
		{
			x1=x+dx[i];
			y1 = y+ dy[i];

			if(x1<0 || x1>=n || y1<0 || y1 >= n)
				continue;

			if(grid[x1][y1] && !visited[x1][y1])
				dfs(x1,y1);

		}

	}

	static class Node{

		int x,y;

		Node(int x,int y)
		{
			this.x=x;this.y=y;
		}
	}

	static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while  (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

import java.awt.Point;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;
import java.util.StringTokenizer;

public class E {

	static int[][] dir = { { 1, 0 }, { 0, 1 }, { -1, 0 }, { 0, -1 } };

	static char[][] m;
	static int id[][], n, k, maxArea;
	static HashMap<Integer, Integer> weight;

	static int bfs(int r, int c) {
		int count = 1;
		int myid = weight.size() + 1;
		id[r][c] = myid;
		Queue<Point> q = new LinkedList<>();
		Point p = new Point(r, c);
		q.offer(p);
		while (!q.isEmpty()) {
			p = q.poll();
			for (int[] d : dir) {
				if (p.x + d[0] >= 0 && p.x + d[0] < n && p.y + d[1] >= 0 && p.y + d[1] < n
						&& id[p.x + d[0]][p.y + d[1]] == 0 && m[p.x + d[0]][p.y + d[1]] == '.') {
					id[p.x + d[0]][p.y + d[1]] = myid;
					count++;
					q.add(new Point(p.x + d[0], p.y + d[1]));
				}
			}
		}
		maxArea = Math.max(maxArea, count);
		weight.put(myid, count);
		return count;
	}

	static boolean check(int r, int c, int dr, int dc) {
		if (r + dr < 0 || r + dr >= n || c + dc < 0 || c + dc >= n || id[r + dr][c + dc] == 0)
			return false;
		return true;
	}

	public static void main(String[] args) throws IOException {
		File inputFile = new File("entradaE");
		if (inputFile.exists())
			System.setIn(new FileInputStream(inputFile));
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder out = new StringBuilder();
		String line = "";
		while ((line = in.readLine()) != null) {
			int[] nk = readInts(line);
			n = nk[0];
			k = nk[1];
			m = new char[n][n];
			id = new int[n][n];
			weight = new HashMap<>(n * n);
			for (int i = 0; i < n; i++)
				m[i] = in.readLine().toCharArray();
			maxArea = 0;
			for (int i = 0; i < n; i++)
				for (int j = 0; j < n; j++)
					if (m[i][j] == '.' && id[i][j] == 0)
						bfs(i, j);
			weight.put(0, 0);
			int[] ids = new int[weight.size()];
			int[] ins = new int[weight.size()];
			int[] w = new int[weight.size()];
			int curTime = 0;
			for (int i = 0; i < w.length; i++)
				w[i] = weight.get(i);
			int theid = 0, cur = 0;
			for (int r = 0; r < k - 1; r++)
				for (int c = 0; c < k - 1; c++)
					ins[id[r][c]]++;
			int pj = 0, dc = 0, qc = 0, pc = 0, qq = 0, sc = 0;
			for (int i = 0; i <= n - k; i++) {
				pj = (i % 2 == 0) ? 0 : n - k + 1;
				dc = (i % 2 == 0) ? 1 : -1;
				qc = (i % 2 == 0) ? -1 : k;
				pc = (i % 2 == 0) ? k - 1 : 0;
				sc = (i % 2 == 0) ? 0 : n - k;
				for (int c = pj; i - 1 >= 0 && c < pj + k - 1; c++)
					ins[id[i - 1][c]]--;
				for (int c = pj; c < pj + k - 1; c++)
					ins[id[i + k - 1][c]]++;
				for (int j = sc; j >= 0 && j <= n - k; j += dc) {
					curTime++;
					for (int r = i; j + qc >= 0 && j + qc < n && r < i + k; r++)
						ins[id[r][j + qc]]--;
					for (int r = i; r < i + k; r++)
						ins[id[r][j + pc]]++;
					// Arrays.fill(ids, false);
					cur = 0;
					// Up
					for (int l = 0; l < k; l++) {
						if (check(i, j + l, -1, 0)) {
							theid = id[i - 1][j + l];
							if (ids[theid] != curTime) {
								ids[theid] = curTime;
								cur += w[theid] - ins[theid];
							}
						}
						// Down
						if (check(i + k - 1, j + l, 1, 0)) {
							theid = id[i + k][j + l];
							if (ids[theid] != curTime) {
								ids[theid] = curTime;
								cur += w[theid] - ins[theid];
							}
						}
						// Left
						if (check(i + l, j, 0, -1)) {
							theid = id[i + l][j - 1];
							if (ids[theid] != curTime) {
								ids[theid] = curTime;
								cur += w[theid] - ins[theid];
							}
						}
						// Right
						if (check(i + l, j + k - 1, 0, 1)) {
							theid = id[i + l][j + k];
							if (ids[theid] != curTime) {
								ids[theid] = curTime;
								cur += w[theid] - ins[theid];
							}
						}
					}
					maxArea = Math.max(maxArea, cur + k * k);
				}
				qq = (i % 2 == 0) ? n - k : k - 1;
				for (int r = i; r < i + k; r++)
					ins[id[r][qq]]--;
			}
			out.append(maxArea + "\n");
		}
		System.out.print(out);
	}

	static int[] readInts(String line) {
		StringTokenizer st = new StringTokenizer(line.trim());
		int a[] = new int[st.countTokens()], index = 0;
		while (st.hasMoreTokens())
			a[index++] = Integer.parseInt(st.nextToken());
		return a;
	}

	static long[] readLongs(String line) {
		StringTokenizer st = new StringTokenizer(line.trim());
		long a[] = new long[st.countTokens()];
		int index = 0;
		while (st.hasMoreTokens())
			a[index++] = Long.parseLong(st.nextToken());
		return a;
	}

	static double[] readDoubles(String line) {
		StringTokenizer st = new StringTokenizer(line.trim());
		double a[] = new double[st.countTokens()];
		int index = 0;
		while (st.hasMoreTokens())
			a[index++] = Double.parseDouble(st.nextToken());
		return a;
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;

public class ProblemC {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		FastScanner input = new FastScanner();
		int n = input.nextInt();
		int limak = input.nextInt();
		int limakFoot = limak * limak;
		char[][] in = new char[n][n];
		for (int a = 0; a < n; a++) {
			in[a] = input.next().toCharArray();
		}
		// Our graph is implicit, so we don't actually need to store the graph.

		// First, we need to do connected components.
		int[][] componentId = new int[n][n];
		for (int a = 0; a < n; a++) {
			for (int b = 0; b < n; b++) {
				componentId[a][b] = -1;
			}
		}
		ArrayList<Integer> componentSizes = new ArrayList<Integer>();
		int component = 0;
		for (int a = 0; a < n; a++) {
			for (int b = 0; b < n; b++) {
				int num = bfs(a, b, in, componentId, component);
				if (num > 0) {
					component++;
					componentSizes.add(num);
				}
			}
		}
		// now we built our connected components
		// we are going to try every single possible bear location. We need to
		// be able to see how large of a connected component such a bear would
		// create.
		// n^3 is OK, n^4 is not. Therefore, we can do operations around the
		// perimiter of each possible spot, but not the area. My initial plan is
		// to go around the grid, and see what components are going inside.
		// Then, take the sum of those components (O(n)), and then do prefix
		// sums to get the number of 'wall' squares inside the grid. (O(n)).
		// Unfortunately, this doesn't handle if there is a connected component
		// entirely hidden under the bear's foot.
		// Could we do dynamic programming? When we start, we could have a
		// hashmap of what is under the foot, and then add/remove such things as
		// we 'move' the foot. This would be O(n) for each move, O(n) to count
		// the components, but it would be O(n^2) on the starting point.
		int bestAnswer = limak * limak;
		for (int a = 0; a < n - limak + 1; a++) {
			// these are all the starting 'x' coordinates
			int b = 0;
			BearFoot foot = startBear(a, b, limak, componentId, componentSizes);
			// startBear calculates what is under the bear's foot.
			for (; b < n - limak + 1; b++) {
//				System.out.println("(" + a + ", " + b + ") " + foot);
				int answer = bearWithMe(foot);
				if (answer > bestAnswer) {
					bestAnswer = answer;
				}
				if (b != n - limak) {
					moveBear(foot, a, b, limak, componentId, componentSizes);
				}
			}
		}
		System.out.println(bestAnswer);
	}

	private static void moveBear(BearFoot foot, int a, int b, int limak,
			int[][] componentId, ArrayList<Integer> componentSizes) {
		// TODO Auto-generated method stub
		for (int c = 0; c < limak; c++) {
			if (componentId[a + c][b] < 0) {
				foot.footStomp--;
			}
		}
		for (int c = 0; c < limak; c++) {
			try {
				if (componentId[a + c][b - 1] >= 0) {
					foot.componentFreq[componentId[a + c][b - 1]]--;
					if (foot.componentFreq[componentId[a + c][b - 1]] == 0) {
						foot.componentSum -= componentSizes.get(componentId[a
								+ c][b - 1]);
					}
				}
			} catch (Exception e) {

			}
		}
		try {
			if (componentId[a - 1][b] >= 0) {
				foot.componentFreq[componentId[a - 1][b]]--;
				if (foot.componentFreq[componentId[a -1][b]] == 0) {
					foot.componentSum -= componentSizes.get(componentId[a-1][b]);
				}
			}
		} catch (Exception e) {

		}
		try {
			if (componentId[a + limak][b] >= 0) {
				foot.componentFreq[componentId[a + limak][b]]--;
				if (foot.componentFreq[componentId[a + limak][b]] == 0) {
					foot.componentSum -= componentSizes.get(componentId[a+ limak][b]);
				}
			}
		} catch (Exception e) {

		}

		for (int c = 0; c < limak; c++) {
			if (componentId[a + c][b + limak] < 0) {
				foot.footStomp++;
			}
		}
		for (int c = 0; c < limak; c++) {
			try {
				if (componentId[a + c][b + limak + 1] >= 0) {
					foot.componentFreq[componentId[a + c][b + limak + 1]]++;
					if (foot.componentFreq[componentId[a + c][b + limak + 1]] == 1) {
						foot.componentSum += componentSizes.get(componentId[a
								+ c][b + limak + 1]);
					}
				}
			} catch (Exception e) {

			}
		}
		try {
			if (componentId[a - 1][b + limak] >= 0) {
				foot.componentFreq[componentId[a - 1][b + limak]]++;
				if (foot.componentFreq[componentId[a -1][b + limak]] == 1) {
					foot.componentSum += componentSizes.get(componentId[a-1][b + limak]);
				}
			}
		} catch (Exception e) {

		}
		try {
			if (componentId[a + limak][b + limak] >= 0) {
				foot.componentFreq[componentId[a + limak][b + limak]]++;
				if (foot.componentFreq[componentId[a + limak][b + limak]] == 1) {
					foot.componentSum += componentSizes.get(componentId[a+ limak][b + limak]);
				}
			}
		} catch (Exception e) {

		}
	}

	private static int bearWithMe(BearFoot foot) {
		// TODO Auto-generated method stub
		return foot.componentSum + foot.footStomp;
	}

	private static BearFoot startBear(int a, int b, int limak,
			int[][] componentId, ArrayList<Integer> componentSizes) {
		// TODO Auto-generated method stub
		int[] componentFreq = new int[componentSizes.size()];
		int footStomp = 0;
		for (int aS = a; aS < a + limak; aS++) {
			for (int bS = b; bS < b + limak; bS++) {
				if (componentId[aS][bS] < 0) {
					footStomp++;
				}
			}
		}
		for (int aS = a - 1; aS < a + limak + 1; aS++) {
			for (int bS = b - 1; bS < b + limak + 1; bS++) {
				boolean aIsBound = aS == a - 1 || aS == a + limak;
				boolean bIsBound = bS == b - 1 || bS == b + limak;
				if (aIsBound && bIsBound) {

				} else {
					try {
						if (componentId[aS][bS] >= 0) {
							componentFreq[componentId[aS][bS]]++;
						}
					} catch (Exception e) {

					}
				}
			}
		}
		int componentSum = 0;
		for (int c = 0; c < componentFreq.length; c++) {
			if (componentFreq[c] > 0) {
				componentSum += componentSizes.get(c);
			}
		}

		return new BearFoot(componentSum, footStomp, componentFreq);
	}

	public static class BearFoot {
		int componentSum;
		int footStomp;
		int[] componentFreq;

		public BearFoot(int _componentSum, int _footStomp, int[] _componentFreq) {
			componentSum = _componentSum;
			footStomp = _footStomp;
			componentFreq = _componentFreq;
		}

		public String toString() {
			return componentSum + " " + footStomp + " "
					+ Arrays.toString(componentFreq);
		}
	}

	private static int bfs(int a, int b, char[][] in, int[][] componentId,
			int component) {
		if (illegalBound(a, b, in) || in[a][b] == 'X'
				|| componentId[a][b] != -1) {
			return 0;
		}
		componentId[a][b] = component;
		int up = bfs(a - 1, b, in, componentId, component);
		int down = bfs(a + 1, b, in, componentId, component);
		int right = bfs(a, b + 1, in, componentId, component);
		int left = bfs(a, b - 1, in, componentId, component);
		return up + down + right + left + 1;
	}

	private static boolean illegalBound(int a, int b, char[][] in) {
		return a < 0 || a >= in.length || b < 0 || b >= in[0].length;
	}

	public static class Point {
		int x;
		int y;

		public Point(int _x, int _y) {
			x = _x;
			y = _y;
		}
	}

	// FASTSCANNER2016
	public static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(Reader in) {
			br = new BufferedReader(in);
		}

		public FastScanner() {
			this(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		// Slightly different from java.util.Scanner.nextLine(),
		// which returns any remaining characters in current line,
		// if any.
		String readNextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}

//package baobab;

import java.io.*;
import java.util.*;

public class E {

    public static void main(String[] args) {
        EIO io = new EIO();
        try {
            Esolver solver = new Esolver(io);
            solver.solve();
        } finally {
            io.close();
        }
    }

}

class Esolver {
    EIO io;

    public Esolver(EIO io) {
        this.io = io;
    }

    static final int UP = 0;
    static final int RIGHT = 1;
    static final int DOWN = 2;
    static final int LEFT = 3;

    public void solve() {
        int n = io.nextInt();
        int k = io.nextInt();
        boolean[][] graph = new boolean[n][n];
        for (int i=0; i<n; i++) {
            String row = io.next();
            for (int j=0; j<row.length(); j++) {
                char c = row.charAt(j);
                graph[i][j] = (c != 'X');
            }
        }
        int largestComponentSize = 0;
        int[] componentSizes = new int[n*n + 2];
        int currentComponent = 1;
        int[][] ofComponent = new int[n][n];
        boolean[][] visited = new boolean[n][n];
        for (int y=0; y<n; y++) {
            for (int x=0; x<n; x++) {
                if (visited[y][x]) continue;
                if (!graph[y][x]) continue;
                ArrayDeque<Pair> q = new ArrayDeque<>();
                q.add(new Pair(y, x));
                int currentSize = 0;
                while (!q.isEmpty()) {
                    Pair curr = q.poll();
                    if (visited[curr.y][curr.x]) continue;
                    if (!graph[curr.y][curr.x]) continue; // X
                    visited[curr.y][curr.x] = true;
                    ofComponent[curr.y][curr.x] = currentComponent;
                    currentSize++;
                    if (curr.y - 1 >= 0) q.add(new Pair(curr.y - 1, curr.x));
                    if (curr.x - 1 >= 0) q.add(new Pair(curr.y, curr.x - 1));
                    if (curr.y + 1 < n) q.add(new Pair(curr.y + 1, curr.x));
                    if (curr.x + 1 < n) q.add(new Pair(curr.y, curr.x + 1));
                }
                componentSizes[currentComponent] = currentSize;
                largestComponentSize = Math.max(largestComponentSize, currentSize);
                currentComponent++;
            }
        }
        int[][][] marks = new int[n][n][4];
        for (int y=0; y<n; y++) {
            for (int x = 0; x < n; x++) {
                if (graph[y][x]) continue;
                // X
                if (y - 1 >= 0) marks[y][x][UP] = ofComponent[y-1][x];
                if (x - 1 >= 0) marks[y][x][LEFT] = ofComponent[y][x-1];
                if (y + 1 < n) marks[y][x][DOWN] = ofComponent[y+1][x];
                if (x + 1 < n) marks[y][x][RIGHT] = ofComponent[y][x+1];
            }
        }
        int maxScore = largestComponentSize;

        for (int y=k; y<=n; y++) {
            int score = 0;
            int[] slidingCount = new int[currentComponent];
            for (int j=y-k; j<y; j++) {
                for (int x=0; x<k; x++) {
                    if (graph[j][x]) continue;
                    score++;
                    for (int direction=0; direction<4; direction++) {
                        int component = marks[j][x][direction];
                        slidingCount[component]++;
                        if (slidingCount[component] == 1) {
                            score += componentSizes[component];
                        }
                    }
                }
            }
            maxScore = Math.max(score, maxScore);
            for (int x=k; x<n; x++) {
                for (int j=y-1; j>=y-k; j--) {
                    if (!graph[j][x-k]) {
                        score--;
                        for (int direction=0; direction<4; direction++) {
                            int component = marks[j][x-k][direction];
                            slidingCount[component]--;
                            if (slidingCount[component] == 0) {
                                score -= componentSizes[component];
                            }
                        }
                    }
                    if (!graph[j][x]) {
                        score++;
                        for (int direction=0; direction<4; direction++) {
                            int component = marks[j][x][direction];
                            slidingCount[component]++;
                            if (slidingCount[component] == 1) {
                                score += componentSizes[component];
                            }
                        }
                    }
                }
                maxScore = Math.max(score, maxScore);
            }
        }
        System.out.println(maxScore);
    }

    private static class Pair {
        int y;
        int x;

        public Pair(int y, int x) {
            this.y = y;
            this.x = x;
        }
    }

    private List<Integer>[] toGraph(EIO io, int n) {
        List<Integer>[] g = new ArrayList[n+1];
        for (int i=1; i<=n; i++) g[i] = new ArrayList<>();
        for (int i=1; i<=n-1; i++) {
            int a = io.nextInt();
            int b = io.nextInt();
            g[a].add(b);
            g[b].add(a);
        }
        return g;
    }
}

class EIO extends PrintWriter {
    private InputStreamReader r;
    private static final int BUFSIZE = 1 << 15;
    private char[] buf;
    private int bufc;
    private int bufi;
    private StringBuilder sb;

    public EIO() {
        super(new BufferedOutputStream(System.out));
        r = new InputStreamReader(System.in);

        buf = new char[BUFSIZE];
        bufc = 0;
        bufi = 0;
        sb = new StringBuilder();
    }

    private void fillBuf() throws IOException {
        bufi = 0;
        bufc = 0;
        while(bufc == 0) {
            bufc = r.read(buf, 0, BUFSIZE);
            if(bufc == -1) {
                bufc = 0;
                return;
            }
        }
    }

    private boolean pumpBuf() throws IOException {
        if(bufi == bufc) {
            fillBuf();
        }
        return bufc != 0;
    }

    private boolean isDelimiter(char c) {
        return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f';
    }

    private void eatDelimiters() throws IOException {
        while(true) {
            if(bufi == bufc) {
                fillBuf();
                if(bufc == 0) throw new RuntimeException("IO: Out of input.");
            }

            if(!isDelimiter(buf[bufi])) break;
            ++bufi;
        }
    }

    public String next() {
        try {
            sb.setLength(0);

            eatDelimiters();
            int start = bufi;

            while(true) {
                if(bufi == bufc) {
                    sb.append(buf, start, bufi - start);
                    fillBuf();
                    start = 0;
                    if(bufc == 0) break;
                }

                if(isDelimiter(buf[bufi])) break;
                ++bufi;
            }

            sb.append(buf, start, bufi - start);

            return sb.toString();
        } catch(IOException e) {
            throw new RuntimeException("IO.next: Caught IOException.");
        }
    }

    public int nextInt() {
        try {
            int ret = 0;

            eatDelimiters();

            boolean positive = true;
            if(buf[bufi] == '-') {
                ++bufi;
                if(!pumpBuf()) throw new RuntimeException("IO.nextInt: Invalid int.");
                positive = false;
            }

            boolean first = true;
            while(true) {
                if(!pumpBuf()) break;
                if(isDelimiter(buf[bufi])) {
                    if(first) throw new RuntimeException("IO.nextInt: Invalid int.");
                    break;
                }
                first = false;

                if(buf[bufi] >= '0' && buf[bufi] <= '9') {
                    if(ret < -214748364) throw new RuntimeException("IO.nextInt: Invalid int.");
                    ret *= 10;
                    ret -= (int)(buf[bufi] - '0');
                    if(ret > 0) throw new RuntimeException("IO.nextInt: Invalid int.");
                } else {
                    throw new RuntimeException("IO.nextInt: Invalid int.");
                }

                ++bufi;
            }

            if(positive) {
                if(ret == -2147483648) throw new RuntimeException("IO.nextInt: Invalid int.");
                ret = -ret;
            }

            return ret;
        } catch(IOException e) {
            throw new RuntimeException("IO.nextInt: Caught IOException.");
        }
    }

    public long nextLong() {
        try {
            long ret = 0;

            eatDelimiters();

            boolean positive = true;
            if(buf[bufi] == '-') {
                ++bufi;
                if(!pumpBuf()) throw new RuntimeException("IO.nextLong: Invalid long.");
                positive = false;
            }

            boolean first = true;
            while(true) {
                if(!pumpBuf()) break;
                if(isDelimiter(buf[bufi])) {
                    if(first) throw new RuntimeException("IO.nextLong: Invalid long.");
                    break;
                }
                first = false;

                if(buf[bufi] >= '0' && buf[bufi] <= '9') {
                    if(ret < -922337203685477580L) throw new RuntimeException("IO.nextLong: Invalid long.");
                    ret *= 10;
                    ret -= (long)(buf[bufi] - '0');
                    if(ret > 0) throw new RuntimeException("IO.nextLong: Invalid long.");
                } else {
                    throw new RuntimeException("IO.nextLong: Invalid long.");
                }

                ++bufi;
            }

            if(positive) {
                if(ret == -9223372036854775808L) throw new RuntimeException("IO.nextLong: Invalid long.");
                ret = -ret;
            }

            return ret;
        } catch(IOException e) {
            throw new RuntimeException("IO.nextLong: Caught IOException.");
        }
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class BearAndSquareGrid {

	static int n, k;
	static char g[][];
	static ArrayList<Integer> cnt;
	static int vis[][];
	static int dx[] = { 0, 0, -1, 1 };
	static int dy[] = { -1, 1, 0, 0 };
	static int cumsum[][];
	static int counted[];
	static int sum = 0;

	static boolean valid(int x, int y) {
		return x >= 0 && y >= 0 && x < n && y < n;
	}

	static boolean valid(int x) {
		return x >= 0 && x < n;
	}

	static int dfs(int i, int j, int idx) {
		if (!valid(i, j) || vis[i][j] != 0 || g[i][j] == 'X')
			return 0;
		vis[i][j] = idx;
		int sum = 1;
		for (int k = 0; k < 4; k++)
			sum += dfs(i + dx[k], j + dy[k], idx);
		return sum;
	}

	static void addCell(int x, int y) {
		int c = vis[x][y];
		counted[c]++;
		if (counted[c] == 1)
			sum += cnt.get(c);
	}

	static void removeCell(int x, int y) {
		int c = vis[x][y];
		counted[c]--;
		if (counted[c] == 0)
			sum -= cnt.get(c);
	}

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(bf.readLine());
		n = Integer.parseInt(st.nextToken());
		k = Integer.parseInt(st.nextToken());
		if (k == n) {
			System.out.println(n * n);
			return;
		}
		g = new char[n][n];
		vis = new int[n][n];
		cumsum = new int[n][n];
		for (int i = 0; i < n; i++)
			g[i] = bf.readLine().toCharArray();
		cnt = new ArrayList<Integer>();
		cnt.add(0);
		int idx = 1;
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				if (vis[i][j] == 0 && g[i][j] == '.')
					cnt.add(dfs(i, j, idx++));
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++) {
				if (i > 0)
					cumsum[i][j] += cumsum[i - 1][j];
				if (j > 0)
					cumsum[i][j] += cumsum[i][j - 1];
				if (i > 0 && j > 0)
					cumsum[i][j] -= cumsum[i - 1][j - 1];
				if (g[i][j] != '.')
					cumsum[i][j]++;
			}
		counted = new int[idx + 1];
		int max = 0;
		sum = 0;
		for (int i = 0; i + k - 1 < n; i++)
			for (int j = 0; j + k - 1 < n; j++) {
				if (j == 0) {
					for (int x = i; x < i + k; x++)
						for (int y = j; y < j + k; y++)
							addCell(x, y);
				} else {
					for (int x = i; x < i + k; x++) {
						removeCell(x, j - 1);
						addCell(x, j + k - 1);
					}
				}
				for (int x = i; x < i + k; x++) {
					if (j - 1 >= 0)
						addCell(x, j - 1);
					if (j + k < n)
						addCell(x, j + k);
				}
				for (int y = j; y < j + k; y++) {
					if (i - 1 >= 0)
						addCell(i - 1, y);
					if (i + k < n)
						addCell(i + k, y);
				}
				int cumm = cumsum[i + k - 1][j + k - 1] - ((i > 0) ? cumsum[i - 1][j + k - 1] : 0)
						- ((j > 0) ? cumsum[i + k - 1][j - 1] : 0) + ((i > 0 && j > 0) ? cumsum[i - 1][j - 1] : 0);
				max = Math.max(max, sum + cumm);
				for (int x = i; x < i + k; x++) {
					if (j - 1 >= 0)
						removeCell(x, j - 1);
					if (j + k < n)
						removeCell(x, j + k);
				}
				for (int y = j; y < j + k; y++) {
					if (i - 1 >= 0)
						removeCell(i - 1, y);
					if (i + k < n)
						removeCell(i + k, y);
				}
				if (j + k == n) {
					for (int x = i; x < i + k; x++)
						for (int y = j; y < j + k; y++)
							removeCell(x, y);
				}
			}
		System.out.println(max);
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

/**
 * Created by birukoudzmitry on 12.06.16.
 */

public class E {

    public static void main(String[] args){

        MyScanner in = new MyScanner();
        int n = in.nextInt();
        int k = in.nextInt();

        DisjointUnionSets dsu = new DisjointUnionSets(n*n);
        Set<Integer> used = new HashSet<>(2*k);

        String[] field = new String[n];
        for(int i=0;i<n;++i){
            field[i] = in.next();
        }

        for(int i=0;i<n;++i){
            for(int j=0;j<n;++j){
                if(field[i].charAt(j)=='.'){
                    if(i>0&&field[i-1].charAt(j)=='.'){
                        dsu.union(i*n+j,(i-1)*n+j);
                    }
                    if(j>0&&field[i].charAt(j-1)=='.'){
                        dsu.union(i*n+j,i*n+j-1);
                    }
                }
            }
        }

        int result = 0;

        int[] components = new int[n*n];

        int dots = 0;
        int except = 0;

        for(int i=0;i<=n-k;++i){
            int startJ = 0;
            int inc = 1;
            if(i%2==1){
                startJ = n-k;
                inc = -1;
            }
            for(int j=startJ;(i%2==1&&j>=0)||(i%2==0&&j<=n-k);j+=inc){

                int allDots = 0;
                used.clear();

                for(int i1=i;i1<i+k;i1++){
                    if(j-1>=0&&field[i1].charAt(j-1)=='.'){
                        allDots+=getDots(used,dsu,i1*n+j-1);
                    }
                    if(j+k<n&&field[i1].charAt(j+k)=='.'){
                        allDots+=getDots(used,dsu,i1*n+j+k);
                    }
                }

                for(int j1=j;j1<j+k;j1++){
                    if(i-1>=0&&field[i-1].charAt(j1)=='.'){
                        allDots+=getDots(used,dsu,(i-1)*n+j1);
                    }
                    if(i+k<n&&field[i+k].charAt(j1)=='.'){
                        allDots+=getDots(used,dsu,(i+k)*n+j1);
                    }
                }

                if(i==0&&j==0){
                    for(int i1=i;i1<i+k;i1++){
                        for(int j1=j;j1<j+k;j1++){
                            if(field[i1].charAt(j1)=='.'){
                                components[dsu.find(i1*n+j1)]++;
                                dots++;
                                if(components[dsu.find(i1*n+j1)]==dsu.size[dsu.find(i1*n+j1)]){
                                    except+=components[dsu.find(i1*n+j1)];
                                }
                            }
                        }
                    }
                }else{
                    int newDots = 0;
                    int oldDots = 0;
                    if(j==startJ){
                        for(int j1=j;j1<j+k;++j1){
                            if(field[i-1].charAt(j1)=='.'){
                                if(components[dsu.find((i-1)*n+j1)]==dsu.size[dsu.find((i-1)*n+j1)]){
                                    except-=dsu.size[dsu.find((i-1)*n+j1)];
                                }
                                components[dsu.find((i-1)*n+j1)]--;
                                oldDots++;
                            }
                        }
                        for(int j1=j;j1<j+k;++j1){
                            if(field[i+k-1].charAt(j1)=='.'){
                                components[dsu.find((i+k-1)*n+j1)]++;
                                if(components[dsu.find((i+k-1)*n+j1)]==dsu.size[dsu.find((i+k-1)*n+j1)]){
                                    except+=components[dsu.find((i+k-1)*n+j1)];
                                }
                                newDots++;
                            }
                        }
                    }else{
                        int prev = j-1;
                        int next = j+k-1;
                        if(i%2==1){
                            prev = j+k;
                            next = j;
                        }
                        for(int i1=i;i1<i+k;++i1){

                            if(field[i1].charAt(prev)=='.'){
                                if(components[dsu.find(i1*n+prev)]==dsu.size[dsu.find(i1*n+prev)]){
                                    except-=dsu.size[dsu.find(i1*n+prev)];
                                }
                                components[dsu.find(i1*n+prev)]--;
                                oldDots++;
                            }
                        }
                        for(int i1=i;i1<i+k;++i1){
                            if(field[i1].charAt(next)=='.'){
                                components[dsu.find(i1*n+next)]++;
                                if(components[dsu.find(i1*n+next)]==dsu.size[dsu.find(i1*n+next)]){
                                    except+=components[dsu.find(i1*n+next)];
                                }
                                newDots++;
                            }
                        }
                    }
                    dots+=(newDots-oldDots);
                }

//                if(allDots+k*k-dots+except>result){
//                    System.out.println(i+" , "+j);
//                    System.out.println(allDots+k*k-dots+except);
//                }
//                System.out.println(i+","+j+" : "+(allDots+k*k-dots+except));
                result = Math.max(result,allDots+k*k-dots+except);
            }
        }
        System.out.println(result);
    }

    private static int getDots(Set<Integer> used, DisjointUnionSets dsu, int index) {
        if(!used.contains(dsu.find(index))){
            used.add(dsu.find(index));
            return dsu.size[dsu.find(index)];
        }
        return 0;
    }

    static class DisjointUnionSets
    {
        int[] rank, parent,size;
        int n;

        // Constructor
        public DisjointUnionSets(int n)
        {
            size = new int[n];
            rank = new int[n];
            parent = new int[n];
            this.n = n;
            makeSet();
        }

        // Creates n sets with single item in each
        void makeSet()
        {
            for (int i=0; i<n; i++)
            {
                // Initially, all elements are in
                // their own set.
                parent[i] = i;
                size[i] = 1;
            }
        }

        // Returns representative of x's set
        int find(int x)
        {
            // Finds the representative of the set
            // that x is an element of
            if (parent[x]!=x)
            {
                // if x is not the parent of itself
                // Then x is not the representative of
                // his set,
                parent[x] = find(parent[x]);

                // so we recursively call Find on its parent
                // and move i's node directly under the
                // representative of this set
            }

            return parent[x];
        }

        // Unites the set that includes x and the set
        // that includes x
        void union(int x, int y)
        {
            // Find representatives of two sets
            int xRoot = find(x), yRoot = find(y);

            // Elements are in the same set, no need
            // to unite anything.
            if (xRoot == yRoot)
                return;

            // If x's rank is less than y's rank
            if (rank[xRoot] < rank[yRoot]) {

                // Then move x under y  so that depth
                // of tree remains less
                parent[xRoot] = yRoot;
                size[yRoot] += size[xRoot];
                // Else if y's rank is less than x's rank
            }else if (rank[yRoot] < rank[xRoot]) {

                // Then move y under x so that depth of
                // tree remains less
                parent[yRoot] = xRoot;
                size[xRoot] += size[yRoot];

            }else // if ranks are the same
            {
                // Then move y under x (doesn't matter
                // which one goes where)
                parent[yRoot] = xRoot;
                size[xRoot]+=size[yRoot];
                // And increment the the result tree's
                // rank by 1
                rank[xRoot] = rank[xRoot] + 1;
            }
        }
    }

    // -----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
    // --------------------------------------------------------

}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author AlexFetisov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE_356 solver = new TaskE_356();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE_356 {
        int n;
        int k;
        boolean[][] f;
        List<Integer> componentCellCount;
        int[][] color;
        int x = 0;
        int y = 0;
        int totalEmpty = 0;
        int sumInComponents = 0;
        int[] amInComponents;
        int[] flag;
        int currentFlagColor = 0;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            n = in.nextInt();
            k = in.nextInt();
            f = new boolean[n][n];
            color = new int[n][n];
            ArrayUtils.fill(color, -1);
            for (int i = 0; i < n; ++i) {
                char[] c = in.nextString().toCharArray();
                for (int j = 0; j < n; ++j) {
                    f[i][j] = (c[j] == '.');
                }
            }

            // Caclulate all CC
            int res = 0;
            componentCellCount = new ArrayList<Integer>();
            int currentComponentId = 0;
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < n; ++j) {
                    if (color[i][j] == -1) {
                        int count = dfs(i, j, currentComponentId++);
                        componentCellCount.add(count);
                        res = Math.max(res, count);
                    }
                }
            }

            flag = new int[currentComponentId];
            amInComponents = new int[currentComponentId];
            // Preprocess first square
            for (int i = 0; i < k; ++i) {
                for (int j = 0; j < k; ++j) {
                    addCell(i, j);
                }
            }

            res = Math.max(res, checkResult());

            for (int i = 0; i <= n - k; ++i) {
                int delta = i % 2 == 0 ? 1 : -1;
                for (int j = 0; j < n - k; ++j) {
                    moveSquare(0, x, y, x, y + delta);
                    y += delta;
                    res = Math.max(res, checkResult());
                }
                if (i != n - k) {
                    moveSquare(1, x, y, x + 1, y);
                    ++x;
                    res = Math.max(res, checkResult());
                }
            }
            out.println(res);
        }

        void moveSquare(int type, int cx, int cy, int nx, int ny) {
            if (type == 0) {
                if (ny < cy) {
                    for (int i = 0; i < k; ++i) {
                        removeCell(cx + i, cy + k - 1);
                        addCell(cx + i, ny);
                    }
                } else {
                    for (int i = 0; i < k; ++i) {
                        removeCell(cx + i, cy);
                        addCell(cx + i, ny + k - 1);
                    }
                }
            } else {
                for (int i = 0; i < k; ++i) {
                    removeCell(cx, cy + i);
                    addCell(nx + k - 1, cy + i);
                }
            }
        }

        void removeCell(int cx, int cy) {
            if (f[cx][cy]) {
                --totalEmpty;
                amInComponents[color[cx][cy]]--;
                if (amInComponents[color[cx][cy]] == 0) {
                    sumInComponents -= componentCellCount.get(color[cx][cy]);
                }
            }
        }

        void addCell(int cx, int cy) {
            if (f[cx][cy]) {
                ++totalEmpty;
                amInComponents[color[cx][cy]]++;
                if (amInComponents[color[cx][cy]] == 1) {
                    sumInComponents += componentCellCount.get(color[cx][cy]);
                }
            }
        }

        int dfs(int cx, int cy, int cId) {
            if (cx < 0 || cx >= n || cy < 0 || cy >= n) return 0;
            if (color[cx][cy] != -1) return 0;
            if (!f[cx][cy]) return 0;
            color[cx][cy] = cId;
            int am = 1;
            am += dfs(cx - 1, cy, cId);
            am += dfs(cx + 1, cy, cId);
            am += dfs(cx, cy - 1, cId);
            am += dfs(cx, cy + 1, cId);
            return am;
        }

        int checkResult() {
            ++currentFlagColor;
            int res = k * k - totalEmpty + sumInComponents;
            for (int i = 0; i < k; ++i) {
                res += checkCell(x - 1, y + i);
                res += checkCell(x + k, y + i);
                res += checkCell(x + i, y - 1);
                res += checkCell(x + i, y + k);
            }
            return res;
        }

        int checkCell(int cx, int cy) {
            if (cx < 0 || cx >= n || cy < 0 || cy >= n) return 0;
            if (!f[cx][cy]) return 0;
            if (amInComponents[color[cx][cy]] > 0) return 0;
            if (flag[color[cx][cy]] == currentFlagColor) return 0;
            flag[color[cx][cy]] = currentFlagColor;
            return componentCellCount.get(color[cx][cy]);
        }

    }

    static class ArrayUtils {
        public static void fill(int[][] f, int value) {
            for (int i = 0; i < f.length; ++i) {
                Arrays.fill(f[i], value);
            }
        }

    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer stt;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                return null;
            }
        }

        public String nextString() {
            while (stt == null || !stt.hasMoreTokens()) {
                stt = new StringTokenizer(nextLine());
            }
            return stt.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

    }
}

import java.util.*;
public class ProE {
	static int n,k,ans,ct,kk,a,res;
	static String ss;
	static int[] mm=new int[250005];
	static int[] pp=new int[250005];
	static int[] qq=new int[250005];
	static char[][] map=new char[505][];
	static int[][] vis=new int[505][505];
	static int[] vx={0,0,1,-1},vy={1,-1,0,0};
	static void dfs(int x,int y)
	{
		vis[x][y]=kk;ct++;
		for(int i=0;i<4;i++)
		{
			int xx=x+vx[i],yy=y+vy[i];
			if(0<xx&&xx<=n&&0<yy&&yy<=n&&vis[xx][yy]==0&&map[xx][yy]!='X')
				dfs(xx,yy);
		}
	}

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		n=in.nextInt();k=in.nextInt();
		for(int i=1;i<=n;i++)
		{
			ss=" "+in.next();
			map[i]=ss.toCharArray();
		}
		for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
		{
			if(vis[i][j]==0&&map[i][j]!='X')
			{
				ct=0;kk++;
				dfs(i,j);mm[kk]=ct;
			}
		}
		ans=0;
		for(int i=1;i<=n-k+1;i++)
		{
			Arrays.fill(pp,0);
			for(int j=0;j<k;j++)
			for(int p=1;p<=k;p++)
			{
				if(map[i+j][p]=='X') continue;
				pp[vis[i+j][p]]++;
			}
			for(int j=1;j<=n-k+1;j++)
			{
				res=0;
				for(int p=0;p<k;p++)
				{
					a=vis[i-1][j+p];
					if(qq[a]==0) { qq[a]=1;res+=mm[a];res-=pp[a];}
					a=vis[i+k][j+p];
					if(qq[a]==0) { qq[a]=1;res+=mm[a];res-=pp[a];}
					a=vis[i+p][j-1];
					if(qq[a]==0) { qq[a]=1;res+=mm[a];res-=pp[a];}
					a=vis[i+p][j+k];
					if(qq[a]==0) { qq[a]=1;res+=mm[a];res-=pp[a];}
				}
				for(int p=0;p<k;p++)
				{
					qq[vis[i-1][j+p]]=0;
					qq[vis[i+k][j+p]]=0;
					qq[vis[i+p][j-1]]=0;
					qq[vis[i+p][j+k]]=0;
				}
				res+=k*k;
				ans=Math.max(ans,res);
				if(j==n-k+1) continue;
				for(int p=0;p<k;p++)
				{
					if(map[i+p][j]!='X')
						pp[vis[i+p][j]]--;
					if(map[i+p][j+k]!='X')
						pp[vis[i+p][j+k]]++;
				}
			}
		}
		System.out.println(ans);
	}
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author AlexFetisov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE_356 solver = new TaskE_356();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE_356 {
        int n;
        int k;
        boolean[][] f;
        int[] componentCellCount;
        int[][] color;
        int x = 0;
        int y = 0;
        int totalEmpty = 0;
        int sumInComponents = 0;
        int[] amInComponents;
        int[] flag;
        int currentFlagColor = 0;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            n = in.nextInt();
            k = in.nextInt();
            f = new boolean[n][n];
            color = new int[n][n];
            ArrayUtils.fill(color, -1);
            for (int i = 0; i < n; ++i) {
                char[] c = in.nextString().toCharArray();
                for (int j = 0; j < n; ++j) {
                    f[i][j] = (c[j] == '.');
                }
            }

            // Caclulate all CC
            int res = 0;
            componentCellCount = new int[n * n];
            int currentComponentId = 0;
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < n; ++j) {
                    if (color[i][j] == -1) {
                        dfs(i, j, currentComponentId);
                        res = Math.max(res, componentCellCount[currentComponentId]);
                        ++currentComponentId;
                    }
                }
            }

            flag = new int[currentComponentId];
            amInComponents = new int[currentComponentId];
            // Preprocess first square
            for (int i = 0; i < k; ++i) {
                for (int j = 0; j < k; ++j) {
                    addCell(i, j);
                }
            }

            res = Math.max(res, checkResult());

            for (int i = 0, delta = 1; i <= n - k; ++i, delta *= -1) {
                for (int j = 0; j < n - k; ++j) {
                    moveSquare(0, x, y, x, y + delta);
                    y += delta;
                    res = Math.max(res, checkResult());
                }
                if (i != n - k) {
                    moveSquare(1, x, y, x + 1, y);
                    ++x;
                    res = Math.max(res, checkResult());
                }
            }
            out.println(res);
        }

        void moveSquare(int type, int cx, int cy, int nx, int ny) {
            if (type == 0) {
                if (ny < cy) {
                    for (int i = 0; i < k; ++i) {
                        removeCell(cx + i, cy + k - 1);
                        addCell(cx + i, ny);
                    }
                } else {
                    for (int i = 0; i < k; ++i) {
                        removeCell(cx + i, cy);
                        addCell(cx + i, ny + k - 1);
                    }
                }
            } else {
                for (int i = 0; i < k; ++i) {
                    removeCell(cx, cy + i);
                    addCell(nx + k - 1, cy + i);
                }
            }
        }

        void removeCell(int cx, int cy) {
            if (f[cx][cy]) {
                --totalEmpty;
                amInComponents[color[cx][cy]]--;
                if (amInComponents[color[cx][cy]] == 0) {
                    sumInComponents -= componentCellCount[color[cx][cy]];
                }
            }
        }

        void addCell(int cx, int cy) {
            if (f[cx][cy]) {
                ++totalEmpty;
                amInComponents[color[cx][cy]]++;
                if (amInComponents[color[cx][cy]] == 1) {
                    sumInComponents += componentCellCount[color[cx][cy]];
                }
            }
        }

        void dfs(int cx, int cy, int cId) {
            if (cx < 0 || cx >= n || cy < 0 || cy >= n) return;
            if (color[cx][cy] != -1) return;
            if (!f[cx][cy]) return;
            componentCellCount[cId]++;
            color[cx][cy] = cId;
            dfs(cx - 1, cy, cId);
            dfs(cx + 1, cy, cId);
            dfs(cx, cy - 1, cId);
            dfs(cx, cy + 1, cId);
        }

        int checkResult() {
            ++currentFlagColor;
            int res = k * k - totalEmpty + sumInComponents;
            for (int i = 0; i < k; ++i) {
                res += checkCell(x - 1, y + i);
                res += checkCell(x + k, y + i);
                res += checkCell(x + i, y - 1);
                res += checkCell(x + i, y + k);
            }
            return res;
        }

        int checkCell(int cx, int cy) {
            if (cx < 0 || cx >= n || cy < 0 || cy >= n) return 0;
            if (!f[cx][cy]) return 0;
            if (amInComponents[color[cx][cy]] > 0) return 0;
            if (flag[color[cx][cy]] == currentFlagColor) return 0;
            flag[color[cx][cy]] = currentFlagColor;
            return componentCellCount[color[cx][cy]];
        }

    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer stt;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                return null;
            }
        }

        public String nextString() {
            while (stt == null || !stt.hasMoreTokens()) {
                stt = new StringTokenizer(nextLine());
            }
            return stt.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

    }

    static class ArrayUtils {
        public static void fill(int[][] f, int value) {
            for (int i = 0; i < f.length; ++i) {
                Arrays.fill(f[i], value);
            }
        }

    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class A {

	static final int[] dx = { 0, 0, -1, 1 };
	static final int[] dy = { -1, 1, 0, 0 };
	static int[][] grid;
	static int N, cnt, inside[], size[];

	static boolean valid(int x, int y) { return x < N && y < N && x > -1 && y > -1 && grid[x][y] == 0; }

	static void dfs(int x, int y, int c)
	{
		grid[x][y] = c;
		size[c]++;
		for(int k = 0; k < 4; ++k)
		{
			int i = x + dx[k], j = y + dy[k];
			if(valid(i, j))
				dfs(i, j, c);
		}
	}

	static void add(int x) { if(inside[x]++ == 0) cnt += size[x]; }

	static void erase(int x) { if(inside[x]-- == 1) cnt -= size[x]; }

	public static void main(String[] args) throws IOException
	{
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		N = sc.nextInt();
		int k = sc.nextInt();
		grid = new int[N][N];
		for(int i = 0; i < N; ++i)
		{
			String s = sc.next();
			for(int j = 0; j < N; ++j)
				if(s.charAt(j) == 'X')
					grid[i][j] = -1;
				else
					grid[i][j] = 0;
		}
		int idx = 0;
		inside = new int[N * N + 1];
		size = new int[N * N + 1];
		for(int i = 0; i < N; ++i)
			for(int j = 0; j < N; ++j)
				if(grid[i][j] == 0)
					dfs(i, j, ++idx);

		for(int i = 0; i < k; ++i)
			for(int j = 0; j < k; ++j)
				if(grid[i][j] == -1)
					++cnt;
				else
					add(grid[i][j]);
		if(k == N)
			out.println(cnt);
		else
		{
			for(int i = 0; i < k; ++i)
			{
				if(grid[i][k] != -1)
					add(grid[i][k]);
				if(grid[k][i] != -1)
					add(grid[k][i]);
			}
			int ans = cnt, d = 1, sx = 0, sy = 0;
			while(true)
			{
				while(sy + d != -1 && sy + d + k <= N)
				{
					if(d == 1)
						goRight(sx, sy++, k);
					else
						goLeft(sx, sy--, k);
					ans = Math.max(ans, cnt);
				}
				if(sx + k == N)
					break;
				goDown(sx++, sy, k);
				ans = Math.max(ans, cnt);
				d *= -1;
			}
			out.println(ans);
		}
		out.flush();
		out.close();
	}

	static void goDown(int sx, int sy, int k)
	{
		if(sx != 0)
			for(int j = sy; j < sy + k; ++j)
				if(grid[sx - 1][j] != -1)
					erase(grid[sx - 1][j]);
		for(int j = sy; j < sy + k; ++j)
			if(grid[sx][j] == -1)
				--cnt;
		if(sy > 0 && grid[sx][sy - 1] != -1)
			erase(grid[sx][sy - 1]);
		if(sy + k < N && grid[sx][sy + k] != -1)
			erase(grid[sx][sy + k]);
		++sx;
		for(int j = sy; j < sy + k; ++j)
			if(grid[sx + k - 1][j] == -1)
				++cnt;
		if(sx + k < N)
			for(int j = sy; j < sy + k; ++j)
				if(grid[sx + k][j] != -1)
					add(grid[sx + k][j]);
		if(sy > 0 && grid[sx + k - 1][sy - 1] != -1)
			add(grid[sx + k - 1][sy - 1]);
		if(sy + k < N && grid[sx + k - 1][sy + k] != -1)
			add(grid[sx + k - 1][sy + k]);
	}

	static void goRight(int sx, int sy, int k)
	{
		if(sy != 0)
			for(int i = sx; i < sx + k; ++i)
				if(grid[i][sy - 1] != -1)
					erase(grid[i][sy - 1]);
		for(int i = sx; i < sx + k; ++i)
			if(grid[i][sy] == -1)
				--cnt;
		if(sx > 0 && grid[sx - 1][sy] != -1)
			erase(grid[sx - 1][sy]);
		if(sx + k < N && grid[sx + k][sy] != -1)
			erase(grid[sx + k][sy]);
		++sy;
		if(sy + k < N)
			for(int i = sx; i < sx + k; ++i)
				if(grid[i][sy + k] != -1)
					add(grid[i][sy + k]);
		for(int i = sx; i < sx + k; ++i)
			if(grid[i][sy + k - 1] == -1)
				++cnt;
		if(sx > 0 && grid[sx - 1][sy + k - 1] != -1)
			add(grid[sx - 1][sy + k - 1]);
		if(sx + k < N && grid[sx + k][sy + k - 1] != -1)
			add(grid[sx + k][sy + k - 1]);
	}

	static void goLeft(int sx, int sy, int k)
	{
		if(sy + k < N)
			for(int i = sx; i < sx + k; ++i)
				if(grid[i][sy + k] != -1)
					erase(grid[i][sy + k]);
		for(int i = sx; i < sx + k; ++i)
			if(grid[i][sy + k - 1] == -1)
				--cnt;
		if(sx > 0 && grid[sx - 1][sy + k - 1] != -1)
			erase(grid[sx - 1][sy + k - 1]);
		if(sx + k < N && grid[sx + k][sy + k - 1] != -1)
			erase(grid[sx + k][sy + k - 1]);
		--sy;
		if(sy != 0)
			for(int i = sx; i < sx + k; ++i)
				if(grid[i][sy - 1] != -1)
					add(grid[i][sy - 1]);
		for(int i = sx; i < sx + k; ++i)
			if(grid[i][sy] == -1)
				++cnt;
		if(sx > 0 && grid[sx - 1][sy] != -1)
			add(grid[sx - 1][sy]);
		if(sx + k < N && grid[sx + k][sy] != -1)
			add(grid[sx + k][sy]);
	}

	static class Scanner
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public String next() throws IOException
		{
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {return Integer.parseInt(next());}

		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}

		public double nextDouble() throws IOException { return Double.parseDouble(next()); }
	}
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Iterator;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.NoSuchElementException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Egor Kulikov (egor@egork.net)
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE {
        private int timer = 0;
        private int n;
        private char[][] tab;
        private int[][] id;
        private IntArrayList square;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            n = in.readInt();
            int k = in.readInt();

            tab = new char[n][n];
            ArrayUtils.fill(tab, 'X');
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    tab[i][j] = in.readCharacter();
                }
            }

            id = new int[n][n];
            ArrayUtils.fill(id, -1);
            square = new IntArrayList();
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if (tab[i][j] == '.' && id[i][j] == -1) {
                        square.add(f(i, j));
                        ++timer;
                    }
                }
            }

            long ansSq = 0;
            timer = 228;
            int[] usedOut = new int[square.size()];

            for (int i = 0; i + k - 1 < n; i++) {
                long sqIn = 0;
                int sumCnt = 0;
                int[] count = new int[square.size()];

                for (int ii = i; ii < i + k; ii++) {
                    for (int jj = 0; jj < k; jj++) {
                        int id = this.id[ii][jj];
                        if (id != -1) {
                            if (count[id] == 0) {
                                sqIn += square.get(id);
                            }
                            ++sumCnt;
                            ++count[id];
                        }
                    }
                }

                for (int j = 0; j + k - 1 < n; j++, ++timer) {
                    int sqOut = 0;
                    for (int ii = i; ii < i + k; ii++) {
                        sqOut += addOut(ii, j - 1, usedOut, count);
                        sqOut += addOut(ii, j + k, usedOut, count);
                    }
                    for (int jj = j; jj < j + k; jj++) {
                        sqOut += addOut(i - 1, jj, usedOut, count);
                        sqOut += addOut(i + k, jj, usedOut, count);
                    }
                    ansSq = Math.max(ansSq, sqIn + sqOut + k * k - sumCnt);

                    if (j + k < n) {
                        for (int ii = i; ii < i + k; ii++) {
                            int id;

                            id = this.id[ii][j + k];
                            if (id != -1) {
                                if (count[id] == 0) {
                                    sqIn += square.get(id);
                                }
                                ++sumCnt;
                                ++count[id];
                            }

                            id = this.id[ii][j];
                            if (id != -1) {
                                if (count[id] == 1) {
                                    sqIn -= square.get(id);
                                }
                                --sumCnt;
                                --count[id];
                            }
                        }
                    }
                }
            }
            out.printLine(ansSq);
        /**/
        }

        private int addOut(int i, int j, int[] used, int[] count) {
            if (!MiscUtils.isValidCell(i, j, n, n)) {
                return 0;
            }
            int id = this.id[i][j];
            if (id == -1) {
                return 0;
            }
            if (count[id] == 0 && used[id] != timer) {
                used[id] = timer;
                return square.get(id);
            }
            return 0;
        }

        private int f(int i, int j) {
            if (MiscUtils.isValidCell(i, j, n, n) && tab[i][j] == '.' && id[i][j] == -1) {
                int ans = 1;
                id[i][j] = timer;
                for (int k = 0; k < 4; k++) {
                    ans += f(i + MiscUtils.DX4[k], j + MiscUtils.DY4[k]);
                }
                return ans;
            } else {
                return 0;
            }
        }

    }

    static interface IntReversableCollection extends IntCollection {
    }

    static interface IntIterator {
        public int value() throws NoSuchElementException;

        public boolean advance();

        public boolean isValid();

    }

    static interface IntCollection extends IntStream {
        public int size();

        default public void add(int value) {
            throw new UnsupportedOperationException();
        }

        default public IntCollection addAll(IntStream values) {
            for (IntIterator it = values.intIterator(); it.isValid(); it.advance()) {
                add(it.value());
            }
            return this;
        }

    }

    static class MiscUtils {
        public static final int[] DX4 = {1, 0, -1, 0};
        public static final int[] DY4 = {0, -1, 0, 1};

        public static boolean isValidCell(int row, int column, int rowCount, int columnCount) {
            return row >= 0 && row < rowCount && column >= 0 && column < columnCount;
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void printLine(long i) {
            writer.println(i);
        }

    }

    static interface IntList extends IntReversableCollection {
        public abstract int get(int index);

        public abstract void addAt(int index, int value);

        public abstract void removeAt(int index);

        default public IntIterator intIterator() {
            return new IntIterator() {
                private int at;
                private boolean removed;

                public int value() {
                    if (removed) {
                        throw new IllegalStateException();
                    }
                    return get(at);
                }

                public boolean advance() {
                    at++;
                    removed = false;
                    return isValid();
                }

                public boolean isValid() {
                    return !removed && at < size();
                }

                public void remove() {
                    removeAt(at);
                    at--;
                    removed = true;
                }
            };
        }

        default public void add(int value) {
            addAt(size(), value);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public char readCharacter() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            return (char) c;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class ArrayUtils {
        public static void fill(int[][] array, int value) {
            for (int[] row : array) {
                Arrays.fill(row, value);
            }
        }

        public static void fill(char[][] array, char value) {
            for (char[] row : array) {
                Arrays.fill(row, value);
            }
        }

    }

    static class IntArrayList extends IntAbstractStream implements IntList {
        private int size;
        private int[] data;

        public IntArrayList() {
            this(3);
        }

        public IntArrayList(int capacity) {
            data = new int[capacity];
        }

        public IntArrayList(IntCollection c) {
            this(c.size());
            addAll(c);
        }

        public IntArrayList(IntStream c) {
            this();
            if (c instanceof IntCollection) {
                ensureCapacity(((IntCollection) c).size());
            }
            addAll(c);
        }

        public IntArrayList(IntArrayList c) {
            size = c.size();
            data = c.data.clone();
        }

        public IntArrayList(int[] arr) {
            size = arr.length;
            data = arr.clone();
        }

        public int size() {
            return size;
        }

        public int get(int at) {
            if (at >= size) {
                throw new IndexOutOfBoundsException("at = " + at + ", size = " + size);
            }
            return data[at];
        }

        private void ensureCapacity(int capacity) {
            if (data.length >= capacity) {
                return;
            }
            capacity = Math.max(2 * data.length, capacity);
            data = Arrays.copyOf(data, capacity);
        }

        public void addAt(int index, int value) {
            ensureCapacity(size + 1);
            if (index > size || index < 0) {
                throw new IndexOutOfBoundsException("at = " + index + ", size = " + size);
            }
            if (index != size) {
                System.arraycopy(data, index, data, index + 1, size - index);
            }
            data[index] = value;
            size++;
        }

        public void removeAt(int index) {
            if (index >= size || index < 0) {
                throw new IndexOutOfBoundsException("at = " + index + ", size = " + size);
            }
            if (index != size - 1) {
                System.arraycopy(data, index + 1, data, index, size - index - 1);
            }
            size--;
        }

    }

    static abstract class IntAbstractStream implements IntStream {

        public String toString() {
            StringBuilder builder = new StringBuilder();
            boolean first = true;
            for (IntIterator it = intIterator(); it.isValid(); it.advance()) {
                if (first) {
                    first = false;
                } else {
                    builder.append(' ');
                }
                builder.append(it.value());
            }
            return builder.toString();
        }

        public boolean equals(Object o) {
            if (!(o instanceof IntStream)) {
                return false;
            }
            IntStream c = (IntStream) o;
            IntIterator it = intIterator();
            IntIterator jt = c.intIterator();
            while (it.isValid() && jt.isValid()) {
                if (it.value() != jt.value()) {
                    return false;
                }
                it.advance();
                jt.advance();
            }
            return !it.isValid() && !jt.isValid();
        }

        public int hashCode() {
            int result = 0;
            for (IntIterator it = intIterator(); it.isValid(); it.advance()) {
                result *= 31;
                result += it.value();
            }
            return result;
        }

    }

    static interface IntStream extends Iterable<Integer>, Comparable<IntStream> {
        public IntIterator intIterator();

        default public Iterator<Integer> iterator() {
            return new Iterator<Integer>() {
                private IntIterator it = intIterator();

                public boolean hasNext() {
                    return it.isValid();
                }

                public Integer next() {
                    int result = it.value();
                    it.advance();
                    return result;
                }
            };
        }

        default public int compareTo(IntStream c) {
            IntIterator it = intIterator();
            IntIterator jt = c.intIterator();
            while (it.isValid() && jt.isValid()) {
                int i = it.value();
                int j = jt.value();
                if (i < j) {
                    return -1;
                } else if (i > j) {
                    return 1;
                }
                it.advance();
                jt.advance();
            }
            if (it.isValid()) {
                return 1;
            }
            if (jt.isValid()) {
                return -1;
            }
            return 0;
        }

    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Iterator;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.NoSuchElementException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top

 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE {
        private int timer = 0;
        private int n;
        private char[][] tab;
        private int[][] id;
        private IntArrayList square;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            n = in.readInt();
            int k = in.readInt();

            tab = new char[n][n];
            ArrayUtils.fill(tab, 'X');
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    tab[i][j] = in.readCharacter();
                }
            }

            id = new int[n][n];
            ArrayUtils.fill(id, -1);
            square = new IntArrayList();
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if (tab[i][j] == '.' && id[i][j] == -1) {
                        square.add(f(i, j));
                        ++timer;
                    }
                }
            }

            long ansSq = 0;
            timer = 228;
            int[] usedOut = new int[square.size()];

            for (int i = 0; i + k - 1 < n; i++) {
                long sqIn = 0;
                int sumCnt = 0;
                int[] count = new int[square.size()];

                for (int ii = i; ii < i + k; ii++) {
                    for (int jj = 0; jj < k; jj++) {
                        int id = this.id[ii][jj];
                        if (id != -1) {
                            if (count[id] == 0) {
                                sqIn += square.get(id);
                            }
                            ++sumCnt;
                            ++count[id];
                        }
                    }
                }

                for (int j = 0; j + k - 1 < n; j++, ++timer) {
                    int sqOut = 0;
                    for (int ii = i; ii < i + k; ii++) {
                        sqOut += addOut(ii, j - 1, usedOut, count);
                        sqOut += addOut(ii, j + k, usedOut, count);
                    }
                    for (int jj = j; jj < j + k; jj++) {
                        sqOut += addOut(i - 1, jj, usedOut, count);
                        sqOut += addOut(i + k, jj, usedOut, count);
                    }
                    ansSq = Math.max(ansSq, sqIn + sqOut + k * k - sumCnt);

                    if (j + k < n) {
                        for (int ii = i; ii < i + k; ii++) {
                            int id;

                            id = this.id[ii][j + k];
                            if (id != -1) {
                                if (count[id] == 0) {
                                    sqIn += square.get(id);
                                }
                                ++sumCnt;
                                ++count[id];
                            }

                            id = this.id[ii][j];
                            if (id != -1) {
                                if (count[id] == 1) {
                                    sqIn -= square.get(id);
                                }
                                --sumCnt;
                                --count[id];
                            }
                        }
                    }
                }
            }
            out.printLine(ansSq);
        /**/
        }

        private int addOut(int i, int j, int[] used, int[] count) {
            if (!MiscUtils.isValidCell(i, j, n, n)) {
                return 0;
            }
            int id = this.id[i][j];
            if (id == -1) {
                return 0;
            }
            if (count[id] == 0 && used[id] != timer) {
                used[id] = timer;
                return square.get(id);
            }
            return 0;
        }

        private int f(int i, int j) {
            if (MiscUtils.isValidCell(i, j, n, n) && tab[i][j] == '.' && id[i][j] == -1) {
                int ans = 1;
                id[i][j] = timer;
                for (int k = 0; k < 4; k++) {
                    ans += f(i + MiscUtils.DX4[k], j + MiscUtils.DY4[k]);
                }
                return ans;
            } else {
                return 0;
            }
        }

    }

    static interface IntReversableCollection extends IntCollection {
    }

    static interface IntIterator {
        public int value() throws NoSuchElementException;

        public boolean advance();

        public boolean isValid();

    }

    static interface IntCollection extends IntStream {
        public int size();

        default public void add(int value) {
            throw new UnsupportedOperationException();
        }

        default public IntCollection addAll(IntStream values) {
            for (IntIterator it = values.intIterator(); it.isValid(); it.advance()) {
                add(it.value());
            }
            return this;
        }

    }

    static class MiscUtils {
        public static final int[] DX4 = {1, 0, -1, 0};
        public static final int[] DY4 = {0, -1, 0, 1};

        public static boolean isValidCell(int row, int column, int rowCount, int columnCount) {
            return row >= 0 && row < rowCount && column >= 0 && column < columnCount;
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void printLine(long i) {
            writer.println(i);
        }

    }

    static interface IntList extends IntReversableCollection {
        public abstract int get(int index);

        public abstract void addAt(int index, int value);

        public abstract void removeAt(int index);

        default public IntIterator intIterator() {
            return new IntIterator() {
                private int at;
                private boolean removed;

                public int value() {
                    if (removed) {
                        throw new IllegalStateException();
                    }
                    return get(at);
                }

                public boolean advance() {
                    at++;
                    removed = false;
                    return isValid();
                }

                public boolean isValid() {
                    return !removed && at < size();
                }

                public void remove() {
                    removeAt(at);
                    at--;
                    removed = true;
                }
            };
        }

        default public void add(int value) {
            addAt(size(), value);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public char readCharacter() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            return (char) c;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class ArrayUtils {
        public static void fill(int[][] array, int value) {
            for (int[] row : array) {
                Arrays.fill(row, value);
            }
        }

        public static void fill(char[][] array, char value) {
            for (char[] row : array) {
                Arrays.fill(row, value);
            }
        }

    }

    static class IntArrayList extends IntAbstractStream implements IntList {
        private int size;
        private int[] data;

        public IntArrayList() {
            this(3);
        }

        public IntArrayList(int capacity) {
            data = new int[capacity];
        }

        public IntArrayList(IntCollection c) {
            this(c.size());
            addAll(c);
        }

        public IntArrayList(IntStream c) {
            this();
            if (c instanceof IntCollection) {
                ensureCapacity(((IntCollection) c).size());
            }
            addAll(c);
        }

        public IntArrayList(IntArrayList c) {
            size = c.size();
            data = c.data.clone();
        }

        public IntArrayList(int[] arr) {
            size = arr.length;
            data = arr.clone();
        }

        public int size() {
            return size;
        }

        public int get(int at) {
            if (at >= size) {
                throw new IndexOutOfBoundsException("at = " + at + ", size = " + size);
            }
            return data[at];
        }

        private void ensureCapacity(int capacity) {
            if (data.length >= capacity) {
                return;
            }
            capacity = Math.max(2 * data.length, capacity);
            data = Arrays.copyOf(data, capacity);
        }

        public void addAt(int index, int value) {
            ensureCapacity(size + 1);
            if (index > size || index < 0) {
                throw new IndexOutOfBoundsException("at = " + index + ", size = " + size);
            }
            if (index != size) {
                System.arraycopy(data, index, data, index + 1, size - index);
            }
            data[index] = value;
            size++;
        }

        public void removeAt(int index) {
            if (index >= size || index < 0) {
                throw new IndexOutOfBoundsException("at = " + index + ", size = " + size);
            }
            if (index != size - 1) {
                System.arraycopy(data, index + 1, data, index, size - index - 1);
            }
            size--;
        }

    }

    static abstract class IntAbstractStream implements IntStream {

        public String toString() {
            StringBuilder builder = new StringBuilder();
            boolean first = true;
            for (IntIterator it = intIterator(); it.isValid(); it.advance()) {
                if (first) {
                    first = false;
                } else {
                    builder.append(' ');
                }
                builder.append(it.value());
            }
            return builder.toString();
        }

        public boolean equals(Object o) {
            if (!(o instanceof IntStream)) {
                return false;
            }
            IntStream c = (IntStream) o;
            IntIterator it = intIterator();
            IntIterator jt = c.intIterator();
            while (it.isValid() && jt.isValid()) {
                if (it.value() != jt.value()) {
                    return false;
                }
                it.advance();
                jt.advance();
            }
            return !it.isValid() && !jt.isValid();
        }

        public int hashCode() {
            int result = 0;
            for (IntIterator it = intIterator(); it.isValid(); it.advance()) {
                result *= 31;
                result += it.value();
            }
            return result;
        }

    }

    static interface IntStream extends Iterable<Integer>, Comparable<IntStream> {
        public IntIterator intIterator();

        default public Iterator<Integer> iterator() {
            return new Iterator<Integer>() {
                private IntIterator it = intIterator();

                public boolean hasNext() {
                    return it.isValid();
                }

                public Integer next() {
                    int result = it.value();
                    it.advance();
                    return result;
                }
            };
        }

        default public int compareTo(IntStream c) {
            IntIterator it = intIterator();
            IntIterator jt = c.intIterator();
            while (it.isValid() && jt.isValid()) {
                int i = it.value();
                int j = jt.value();
                if (i < j) {
                    return -1;
                } else if (i > j) {
                    return 1;
                }
                it.advance();
                jt.advance();
            }
            if (it.isValid()) {
                return 1;
            }
            if (jt.isValid()) {
                return -1;
            }
            return 0;
        }

    }
}

import java.util.*;
import java.io.*;
/*
5 3
.....
.XXX.
.XXX.
.XXX.
.....

3 1
...
XXX
...

3 1
X.X
.X.
X.X
 */
public class a
{
	public static void main(String[] args) throws IOException
	{
		new a();
	}
	int n;
	int k;
	String[] g;
	int[][] grid;
	boolean[][] used;
	ArrayList<Integer> cnt;
	int[] dr = new int[]{-1, 1, 0, 0};
	int[] dc = new int[]{0, 0, -1, 1};
	public a() throws IOException
	{
		FastScanner in = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		n = in.nextInt();
		k = in.nextInt();
//		if(n == 1)
//		{
//			String s = in.next();
//			System.out.println(1);
//		}
//		else
//		{
			g = new String[n];
			for(int i = 0; i < n; i++) g[i] = in.next();
			grid = new int[n][n];
			for(int[] a : grid) Arrays.fill(a, -1);
			used = new boolean[n][n];
			cnt = new ArrayList<Integer>();
			for(int i = 0; i < n; i++)
			{
				for(int j = 0; j < n; j++)
				{
					if(g[i].charAt(j) == '.' && !used[i][j])
					{
						used[i][j] = true;
						grid[i][j] = cnt.size();
						cnt.add(floodfill(i, j, cnt.size()));
					}
				}
			}

			long ret = 0;
			for(int i = 0; i < cnt.size(); i++) ret = Math.max(ret, cnt.get(i));
			ret = Math.max(ret, k*k);
			for(int i = 0; i <= n-k; i++)
			{
				int lp = 0;
				int rp = -1;
				int total = 0;
				int[] u = new int[cnt.size()];
				while(rp < n)
				{
					rp++;
					if(rp >= n) break;
					for(int j = 0; j < k; j++)
					{
						if(g[i+j].charAt(rp) == 'X')
						{
							total++;
						}
						if(grid[i+j][rp] != -1)
						{
							int num = grid[i+j][rp];
							if(u[num] == 0)
							{
								total += cnt.get(num);
							}
							u[num]++;
						}
					}

					if(rp-lp+1 > k)
					{
						for(int j = 0; j < k; j++)
						{
							if(g[i+j].charAt(lp) == 'X')
							{
								total--;
							}
							if(grid[i+j][lp] != -1)
							{
								int num = grid[i+j][lp];
								if(u[num] == 1)
								{
									total -= cnt.get(num);
								}
								u[num]--;
							}
						}
						lp++;
					}

					if(rp-lp+1 == k)
					{
						int extra = 0;
						HashSet<Integer> hs = new HashSet<Integer>();
						if(i-1 >= 0)
						{
							for(int ii = 0; ii < k; ii++)
							{
								if(grid[i-1][lp+ii] != -1)
								{
									if(hs.add(grid[i-1][lp+ii]) && u[grid[i-1][lp+ii]] == 0)
									{
										extra += cnt.get(grid[i-1][lp+ii]);
									}
								}
							}
						}
						if(i+k < n)
						{
							for(int ii = 0; ii < k; ii++)
							{
								if(grid[i+k][lp+ii] != -1)
								{
									if(hs.add(grid[i+k][lp+ii]) && u[grid[i+k][lp+ii]] == 0)
									{
										extra += cnt.get(grid[i+k][lp+ii]);
									}
								}
							}
						}
						if(lp-1 >= 0)
						{
							for(int ii = 0; ii < k; ii++)
							{
								if(grid[i+ii][lp-1] != -1)
								{
									if(hs.add(grid[i+ii][lp-1]) && u[grid[i+ii][lp-1]] == 0)
									{
										extra += cnt.get(grid[i+ii][lp-1]);
									}
								}
							}
						}
						if(rp+1 < n)
						{
							for(int ii = 0; ii < k; ii++)
							{
								if(grid[i+ii][rp+1] != -1)
								{
									if(hs.add(grid[i+ii][rp+1]) && u[grid[i+ii][rp+1]] == 0)
									{
										extra += cnt.get(grid[i+ii][rp+1]);
									}
								}
							}
						}
						ret = Math.max(ret, total+extra);
					}
				}
			}
			System.out.println(ret);
//		}
		in.close(); out.close();
	}
	int floodfill(int r, int c, int mark)
	{
		int ret = 1;
		for(int i = 0; i < 4; i++)
		{
			int nr = r+dr[i];
			int nc = c+dc[i];
			if(in_bound(nr,nc) && !used[nr][nc] && g[nr].charAt(nc) == '.')
			{
				used[nr][nc] = true;
				grid[nr][nc] = mark;
				ret += floodfill(nr, nc, mark);
			}
		}
		return ret;
	}
	boolean in_bound(int r, int c)
	{
		return 0 <= r && r < n && 0 <= c && c < n;
	}
	class FastScanner
	{
		BufferedReader br;
		StringTokenizer st;
		public FastScanner(InputStream in)
		{
			br = new BufferedReader(new InputStreamReader(in));
			st = new StringTokenizer("");
		}
		public String next() throws IOException
		{
			while(!st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int nextInt() throws IOException
		{
			return Integer.parseInt(next());
		}
		public long nextLong() throws IOException
		{
			return Long.parseLong(next());
		}
		public void close() throws IOException
		{
			br.close();
		}
	}

}

import java.util.*;
import java.io.*;
import java.math.*;

public class Main {

	BufferedReader in;
	StringTokenizer str = null;
	PrintWriter out;

	private String next() throws Exception{
		while (str == null || !str.hasMoreElements())
			str = new StringTokenizer(in.readLine());
		return str.nextToken();
	}

	private int nextInt() throws Exception{
		return Integer.parseInt(next());
	}

	private long nextLong() throws Exception{
		return Long.parseLong(next());
	}

	private double nextDouble() throws Exception{
		return Double.parseDouble(next());
	}

	final long oo = Long.MAX_VALUE;

	final int []di = new int[]{-1, 1, 0, 0};
	final int []dj = new int[]{0, 0, -1, 1};

	int n, k;

	boolean [][]map;
	int [][]color;
	List<Integer> compSum;

	int emptyAll, curFlag, sumAll;
	int []amInComponent;
	int []curColorFlag;

	int curX, curY;

	public void run() throws Exception{
		in =  new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		n = nextInt();
		k = nextInt();

		map = new boolean[n][n];
		for(int i = 0; i < n; ++i) {
			String s = next();
			for(int j = 0; j < n; ++j) {
				map[i][j] = s.charAt(j) == '.';
			}
		}

		compSum = new ArrayList<>();
		color = new int[n][n];
		for(int []i : color) {
			Arrays.fill(i, -1);
		}
		int curColor = 0;

		int ret = 0;
		for(int i = 0; i < n; ++i) {
			for(int j = 0; j < n; ++j) {
				if (color[i][j] == -1 && map[i][j]) {
					int size = dfs(i, j, curColor++);
					compSum.add(size);
					// System.out.println("size = " + size + " " + i + " " + j);
					ret = Math.max(ret, size);
				}
			}
		}

		amInComponent = new int[compSum.size()];
		curColorFlag = new int[compSum.size()];

		for(int i = 0; i < k; ++i)
			for(int j = 0; j < k; ++j)
				addCell(i, j);

		ret = Math.max(ret, checkResult());

		for(int i = 0; i <= n - k; ++i) {
			int dy = (i % 2 == 0) ? 1 : -1;
			for(int j = 0; j < n - k; ++j) {
				move(0, curX, curY, curX, curY + dy);
				curY += dy;

				ret = Math.max(ret, checkResult());
			}
			if (i != n - k) {
				move(1, curX, curY, curX + 1, curY);
				curX += 1;

				ret = Math.max(ret, checkResult());
			}
		}

		out.println(ret);
		out.close();
	}

	private int dfs(int x, int y, int curColor) {
		if (x < 0 || y < 0 || x >= n || y >= n) return 0;
		if (!map[x][y]) return 0;
		if (color[x][y] != -1) return 0;
		color[x][y] = curColor;

		int ret = 1;
		for(int i = 0 ; i < 4; ++i) {
			ret += dfs(x + di[i], y + dj[i], curColor);
		}

		return ret;
	}

	private void move(int type, int x, int y, int nx, int ny) {
		if (type == 0) {
			if (y < ny) {
				for(int i = 0; i < k; ++i) {
					removeCell(x + i, y);
					addCell(x + i, y + k);
				}
			} else {
				for(int i = 0; i < k; ++i) {
					removeCell(x + i, ny + k);
					addCell(x + i, ny);
				}
			}
		} else {
			for(int i = 0; i < k; ++i) {
				removeCell(x, y + i);
				addCell(x + k, y + i);
			}
		}
	}

	private void addCell(int x, int y) {
		if (!map[x][y]) return;
		++emptyAll;
		++amInComponent[color[x][y]];
		if (amInComponent[color[x][y]] == 1) {
			sumAll += compSum.get(color[x][y]);
		}
	}

	private void removeCell(int x, int y) {
		if (!map[x][y]) return;
		--emptyAll;
		--amInComponent[color[x][y]];
		if (amInComponent[color[x][y]] == 0) {
			sumAll -= compSum.get(color[x][y]);
		}
	}

	private int checkResult() {
		++curFlag;
		int ret = k * k - emptyAll + sumAll;
		for(int i = 0; i < k; ++i) {
			ret += add(curX - 1, curY + i);
			ret += add(curX + k, curY + i);
			ret += add(curX + i, curY - 1);
			ret += add(curX + i, curY + k);
		}

		return ret;
	}

	private int add(int x, int y) {
		if (x < 0 || y < 0 || x >= n || y >= n) return 0;
		if (!map[x][y]) return 0;
		if (amInComponent[color[x][y]] > 0) return 0;
		if (curColorFlag[color[x][y]] == curFlag) return 0;

		curColorFlag[color[x][y]] = curFlag;
		return compSum.get(color[x][y]);
	}

	public static void main(String[] args) throws Exception{
		new Main().run();
	}
}

import java.awt.Point;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;

public class E {

	static int[][] dir = { { 1, 0 }, { 0, 1 }, { -1, 0 }, { 0, -1 } };

	static char[][] m;
	static int id[][], n, k, maxArea;
	static HashMap<Integer, Integer> weight;

	static int bfs(int r, int c) {
		int count = 1;
		int myid = weight.size() + 1;
		id[r][c] = myid;
		Queue<Point> q = new LinkedList<>();
		Point p = new Point(r, c);
		q.offer(p);
		while (!q.isEmpty()) {
			p = q.poll();
			for (int[] d : dir) {
				if (p.x + d[0] >= 0 && p.x + d[0] < n && p.y + d[1] >= 0 && p.y + d[1] < n
						&& id[p.x + d[0]][p.y + d[1]] == 0 && m[p.x + d[0]][p.y + d[1]] == '.') {
					id[p.x + d[0]][p.y + d[1]] = myid;
					count++;
					q.add(new Point(p.x + d[0], p.y + d[1]));
				}
			}
		}
		maxArea = Math.max(maxArea, count);
		weight.put(myid, count);
		return count;
	}

	static boolean check(int r, int c, int dr, int dc) {
		if (r + dr < 0 || r + dr >= n || c + dc < 0 || c + dc >= n || id[r + dr][c + dc] == 0)
			return false;
		return true;
	}

	public static void main(String[] args) throws IOException {
		File inputFile = new File("entradaE");
		if (inputFile.exists())
			System.setIn(new FileInputStream(inputFile));
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder out = new StringBuilder();
		String line = "";
		while ((line = in.readLine()) != null) {
			int[] nk = readInts(line);
			n = nk[0];
			k = nk[1];
			m = new char[n][n];
			id = new int[n][n];
			weight = new HashMap<>(n * n);
			for (int i = 0; i < n; i++)
				m[i] = in.readLine().toCharArray();
			maxArea = 0;
			for (int i = 0; i < n; i++)
				for (int j = 0; j < n; j++)
					if (m[i][j] == '.' && id[i][j] == 0)
						bfs(i, j);
			weight.put(0, 0);
			int[] ids = new int[weight.size()];
			int[] ins = new int[weight.size()];
			int[] w = new int[weight.size()];
			int curTime = 0;
			for (int i = 0; i < w.length; i++)
				w[i] = weight.get(i);
			int theid = 0, cur = 0;
			for (int r = 0; r < k - 1; r++)
				for (int c = 0; c < k - 1; c++)
					ins[id[r][c]]++;
			int pj = 0, dc = 0, qc = 0, pc = 0, qq = 0, sc = 0;
			for (int i = 0; i <= n - k; i++) {
				pj = (i % 2 == 0) ? 0 : n - k + 1;
				dc = (i % 2 == 0) ? 1 : -1;
				qc = (i % 2 == 0) ? -1 : k;
				pc = (i % 2 == 0) ? k - 1 : 0;
				sc = (i % 2 == 0) ? 0 : n - k;
				for (int c = pj; i - 1 >= 0 && c < pj + k - 1; c++)
					ins[id[i - 1][c]]--;
				for (int c = pj; c < pj + k - 1; c++)
					ins[id[i + k - 1][c]]++;
				for (int j = sc; j >= 0 && j <= n - k; j += dc) {
					curTime++;
					for (int r = i; j + qc >= 0 && j + qc < n && r < i + k; r++)
						ins[id[r][j + qc]]--;
					for (int r = i; r < i + k; r++)
						ins[id[r][j + pc]]++;
					cur = 0;
					// Up
					for (int l = 0; l < k; l++)
						if (check(i, j + l, -1, 0)) {
							theid = id[i - 1][j + l];
							if (ids[theid] != curTime) {
								ids[theid] = curTime;
								cur += w[theid] - ins[theid];
							}
						}
					// Down
					for (int l = 0; l < k; l++)
						if (check(i + k - 1, j + l, 1, 0)) {
							theid = id[i + k][j + l];
							if (ids[theid] != curTime) {
								ids[theid] = curTime;
								cur += w[theid] - ins[theid];
							}
						}
					// Left
					for (int l = 0; l < k; l++)
						if (check(i + l, j, 0, -1)) {
							theid = id[i + l][j - 1];
							if (ids[theid] != curTime) {
								ids[theid] = curTime;
								cur += w[theid] - ins[theid];
							}
						}
					// Right
					for (int l = 0; l < k; l++)
						if (check(i + l, j + k - 1, 0, 1)) {
							theid = id[i + l][j + k];
							if (ids[theid] != curTime) {
								ids[theid] = curTime;
								cur += w[theid] - ins[theid];
							}
						}
					maxArea = Math.max(maxArea, cur + k * k);
				}
				qq = (i % 2 == 0) ? n - k : k - 1;
				for (int r = i; r < i + k; r++)
					ins[id[r][qq]]--;
			}
			out.append(maxArea + "\n");
		}
		System.out.print(out);
	}

	static int[] readInts(String line) {
		StringTokenizer st = new StringTokenizer(line.trim());
		int a[] = new int[st.countTokens()], index = 0;
		while (st.hasMoreTokens())
			a[index++] = Integer.parseInt(st.nextToken());
		return a;
	}

	static long[] readLongs(String line) {
		StringTokenizer st = new StringTokenizer(line.trim());
		long a[] = new long[st.countTokens()];
		int index = 0;
		while (st.hasMoreTokens())
			a[index++] = Long.parseLong(st.nextToken());
		return a;
	}

	static double[] readDoubles(String line) {
		StringTokenizer st = new StringTokenizer(line.trim());
		double a[] = new double[st.countTokens()];
		int index = 0;
		while (st.hasMoreTokens())
			a[index++] = Double.parseDouble(st.nextToken());
		return a;
	}
}

/*
 http://codeforces.com/contest/679/problem/C

 Let's first find CC's (connected components) in the given grid, using DFS's.
We will consider every possible placement of a k × k square. When the placement is fixed then the answer is equal to the sum of k2 the the sum of sizes of CC's touching borders of the square (touching from outside), but for those CC's we should only count their cells that are outside of the square — not to count something twice. We will move a square, and at the same time for each CC we will keep the number of its cells outside the square.
We will used a sliding-window technique. Let's fix row of the grid — the upper row of the square. Then, we will first place the square on the left, and then we will slowly move a square to the right. As we move a square, we should iterate over cells that stop or start to belong to the square. For each such empty cell we should add or subtract 1 from the size of its CC (ids and sizes of CC's were found at the beginning).
And for each placement we consider, we should iterate over outside borders of the square (4k cells — left, up, right and down side) and sum up sizes of CC's touching our square. Be careful to not count some CC twice — you can e.g. keep an array of booleans and mark visited CC's. After checking all 4k cells you should clear an array, but you can't do it in O(number_of_all_components) because it would be too slow. You can e.g. also add visited CC's to some vector, and later in the boolean array clear only CC's from the vector (and then clear vector).
 */
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author AlexFetisov
 */
public class BearAndSquareGrid679C {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskE_356 solver = new TaskE_356();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskE_356 {
		int n;
		int k;
		boolean[][] f;
		List<Integer> componentCellCount;
		int[][] color;
		int x = 0;
		int y = 0;
		int totalEmpty = 0;
		int sumInComponents = 0;
		int[] amInComponents;
		int[] flag;
		int currentFlagColor = 0;

		public void solve(int testNumber, InputReader in, PrintWriter out) {
			n = in.nextInt();
			k = in.nextInt();
			f = new boolean[n][n];
			color = new int[n][n];
			ArrayUtils.fill(color, -1);
			for (int i = 0; i < n; ++i) {
				char[] c = in.nextString().toCharArray();
				for (int j = 0; j < n; ++j) {
					f[i][j] = (c[j] == '.');
				}
			}

			// Caclulate all CC
			int res = 0;
			componentCellCount = new ArrayList<Integer>();
			int currentComponentId = 0;
			for (int i = 0; i < n; ++i) {
				for (int j = 0; j < n; ++j) {
					if (color[i][j] == -1) {
						int count = dfs(i, j, currentComponentId++);
						componentCellCount.add(count);
						res = Math.max(res, count);
					}
				}
			}

			flag = new int[currentComponentId];
			amInComponents = new int[currentComponentId];
			// Preprocess first square
			for (int i = 0; i < k; ++i) {
				for (int j = 0; j < k; ++j) {
					addCell(i, j);
				}
			}

			res = Math.max(res, checkResult());

			for (int i = 0; i <= n - k; ++i) {
				int delta = i % 2 == 0 ? 1 : -1;
				for (int j = 0; j < n - k; ++j) {
					moveSquare(0, x, y, x, y + delta);
					y += delta;
					res = Math.max(res, checkResult());
				}
				if (i != n - k) {
					moveSquare(1, x, y, x + 1, y);
					++x;
					res = Math.max(res, checkResult());
				}
			}
			out.println(res);
		}

		void moveSquare(int type, int cx, int cy, int nx, int ny) {
			if (type == 0) {
				if (ny < cy) {
					for (int i = 0; i < k; ++i) {
						removeCell(cx + i, cy + k - 1);
						addCell(cx + i, ny);
					}
				} else {
					for (int i = 0; i < k; ++i) {
						removeCell(cx + i, cy);
						addCell(cx + i, ny + k - 1);
					}
				}
			} else {
				for (int i = 0; i < k; ++i) {
					removeCell(cx, cy + i);
					addCell(nx + k - 1, cy + i);
				}
			}
		}

		void removeCell(int cx, int cy) {
			if (f[cx][cy]) {
				--totalEmpty;
				amInComponents[color[cx][cy]]--;
				if (amInComponents[color[cx][cy]] == 0) {
					sumInComponents -= componentCellCount.get(color[cx][cy]);
				}
			}
		}

		void addCell(int cx, int cy) {
			if (f[cx][cy]) {
				++totalEmpty;
				amInComponents[color[cx][cy]]++;
				if (amInComponents[color[cx][cy]] == 1) {
					sumInComponents += componentCellCount.get(color[cx][cy]);
				}
			}
		}

		int dfs(int cx, int cy, int cId) {
			if (cx < 0 || cx >= n || cy < 0 || cy >= n)
				return 0;
			if (color[cx][cy] != -1)
				return 0;
			if (!f[cx][cy])
				return 0;
			color[cx][cy] = cId;
			int am = 1;
			am += dfs(cx - 1, cy, cId);
			am += dfs(cx + 1, cy, cId);
			am += dfs(cx, cy - 1, cId);
			am += dfs(cx, cy + 1, cId);
			return am;
		}

		int checkResult() {
			++currentFlagColor;
			int res = k * k - totalEmpty + sumInComponents;
			for (int i = 0; i < k; ++i) {
				res += checkCell(x - 1, y + i);
				res += checkCell(x + k, y + i);
				res += checkCell(x + i, y - 1);
				res += checkCell(x + i, y + k);
			}
			return res;
		}

		int checkCell(int cx, int cy) {
			if (cx < 0 || cx >= n || cy < 0 || cy >= n)
				return 0;
			if (!f[cx][cy])
				return 0;
			if (amInComponents[color[cx][cy]] > 0)
				return 0;
			if (flag[color[cx][cy]] == currentFlagColor)
				return 0;
			flag[color[cx][cy]] = currentFlagColor;
			return componentCellCount.get(color[cx][cy]);
		}

	}

	static class ArrayUtils {
		public static void fill(int[][] f, int value) {
			for (int i = 0; i < f.length; ++i) {
				Arrays.fill(f[i], value);
			}
		}

	}

	static class InputReader {
		private BufferedReader reader;
		private StringTokenizer stt;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
		}

		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				return null;
			}
		}

		public String nextString() {
			while (stt == null || !stt.hasMoreTokens()) {
				stt = new StringTokenizer(nextLine());
			}
			return stt.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

	}
}

import java.util.HashSet;
import java.util.Scanner;

public class Problem679C {
	int N, K;
	char data[][] = new char[600][600];
	int color[][] = new int[600][600];
	int colorCount[] = new int[600 * 600];
	int maxColor = 1;
	int inCol[] = new int[600 * 600];
	int inCount = 0;

	public void run() {
		Scanner scanner = new Scanner(System.in);
		N = scanner.nextInt();
		K = scanner.nextInt();
		scanner.nextLine();
		for (int r = 0; r < N; ++r) {
			String line = scanner.nextLine();
			for (int c = 0; c < N; ++c) {
				data[r][c] = line.charAt(c);
			}
		}
		for (int r = 0; r < N; ++r) {
			for (int c = 0; c < N; ++c) {
				if (data[r][c] == '.' && color[r][c] == 0) {
					runColor(r, c, maxColor);
					++maxColor;
				}
			}
		}

		for (int kr = 0; kr < K; ++kr) {
			for (int kc = 0; kc < K; ++kc) {
				add(kr, kc);
			}
		}

		int ans = runRow();
		System.out.println(ans);
	}

	private int runRow() {
		int best = inCount;
		for (int r = 0; r < N - K + 1; ++r) {
			if (r > 0) {
				int top = r - 1, bot = r + K - 1;
				for (int kc = 0; kc < K; ++kc) {
					add(bot, kc);
					del(top, kc);
				}
			}
			int result = runCol(r);
			best = Math.max(best, result);
		}
		return best;
	}

	private int runCol(int r) {
		int best = inCount;
		int savedInCount = inCount;
		int savedInCol[] = new int[600*600];
		for (int i = 0; i <= maxColor; ++i) {
			savedInCol[i] = inCol[i];
		}
		for (int c = 0; c < N - K + 1; ++c) {
			if (c > 0) {
				int left = c - 1, right = c + K - 1;
				for (int kr = 0; kr < K; ++kr) {
					add(kr + r, right);
					del(kr + r, left);
				}
			}
			int total = inCount + addBorder(r, c);
			//System.out.println("r=" + r + " c=" + c + " inCount=" + inCount
			//		+ " total=" + total);
			best = Math.max(best, total);
		}
		inCol = savedInCol;
		inCount = savedInCount;
		return best;
	}

	private int addBorder(int r, int c) {
		int borderCount = 0;
		HashSet<Integer> inBorder = new HashSet<Integer>();
		if (c > 0) {
			for (int kr = 0; kr < K; ++kr) {
				borderCount += addBorderCell(r + kr, c - 1, inBorder);
			}
		}
		if (c + K < N) {
			for (int kr = 0; kr < K; ++kr) {
				borderCount += addBorderCell(r + kr, c + K, inBorder);
			}
		}
		if (r > 0) {
			for (int kc = 0; kc < K; ++kc) {
				borderCount += addBorderCell(r - 1, c + kc, inBorder);
			}
		}
		if (r + K < N) {
			for (int kc = 0; kc < K; ++kc) {
				borderCount += addBorderCell(r + K, c + kc, inBorder);
			}
		}
		return borderCount;
	}

	private int addBorderCell(int r, int c, HashSet<Integer> inBorder) {
		int z = color[r][c];
		if (z == 0) {
			return 0;
		}
		if (inCol[z] == 0) {
			if (inBorder.add(z)) {
				return colorCount[z];
			}
		}
		return 0;
	}

	private void add(int r, int c) {
		int z = color[r][c];
		if (z == 0) {
			++inCount;
			return;
		}
		if (inCol[z] == 0) {
			inCount += colorCount[z];
		}
		inCol[z]++;
	}

	private void del(int r, int c) {
		int z = color[r][c];
		if (z == 0) {
			--inCount;
			return;
		}
		inCol[z]--;
		if (inCol[z] == 0) {
			inCount -= colorCount[z];
		}
	}

	public static void main(String[] args) {
		new Problem679C().run();
	}

	private void runColor(int r, int c, int z) {
		if (r < 0 || c < 0 || r >= N || c >= N) {
			return;
		}
		if (color[r][c] != 0) {
			return;
		}
		if (data[r][c] != '.') {
			return;
		}
		colorCount[z]++;
		color[r][c] = z;
		runColor(r-1, c, z);
		runColor(r, c-1, z);
		runColor(r+1, c, z);
		runColor(r, c+1, z);
	}
}

import java.io.*;
import java.util.*;

public class CF {
	FastScanner in;
	PrintWriter out;

	int[][] cId;
	int comps = 0;

	int[] dx = new int[] { -1, 0, 0, 1 };
	int[] dy = new int[] { 0, -1, 1, 0 };
	int n;

	void go(int x, int y) {
		if (x < 0 || y < 0 || x >= n || y >= n) {
			return;
		}
		if (cId[x][y] != -1 || a[x][y] == 'X') {
			return;
		}
		cId[x][y] = comps;
		for (int it = 0; it < dx.length; it++) {
			go(x + dx[it], y + dy[it]);
		}
	}
	char[][] a;

	void solve() {
		n = in.nextInt();
		int k = in.nextInt();
		a = new char[n][];
		for (int i = 0; i < n; i++) {
			a[i] = in.next().toCharArray();
		}
		cId = new int[n][n];
		for (int i = 0; i < n; i++) {
			Arrays.fill(cId[i], -1);
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (cId[i][j] == -1 && a[i][j] == '.') {
					go(i, j);
					comps++;
				}
			}
		}
		sz = new int[comps];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (cId[i][j] != -1) {
					sz[cId[i][j]]++;
				}
			}
		}
		int best = 0;
		int[][] sum = new int[n + 1][n + 1];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				sum[i + 1][j + 1] = sum[i + 1][j] + sum[i][j + 1] - sum[i][j];
				if (a[i][j] == '.') {
					sum[i + 1][j + 1]++;
				}
			}
		}
		cnt = new int[comps];
		for (int stX = 0; stX + k <= n; stX++) {
			Arrays.fill(cnt, 0);
			sumSizes = k * k;
			for (int i = 0; i < k; i++) {
				for (int j = -1; j <= k; j++) {
					add(stX + i, j);
				}
			}
			for (int i = 0; i < k; i++) {
				add(stX - 1, i);
				add(stX + k, i);
			}
			for (int stY = 0; stY + k <= n; stY++) {
				int curAns = sum[stX + k][stY + k] - sum[stX][stY + k]
						- sum[stX + k][stY] + sum[stX][stY];
				curAns = -curAns + sumSizes;
				best = Math.max(best, curAns);
				for (int i = 0; i < k; i++) {
					rem(stX + i, stY - 1);
					add(stX + i, stY + k + 1);
				}
				rem(stX - 1, stY);
				rem(stX + k, stY);
				add(stX - 1, stY + k);
				add(stX + k, stY + k);
			}
		}
		out.println(best);
	}

	int sumSizes;

	void add(int x, int y) {
		if (x < 0 || x >= n || y < 0 || y >= n) {
			return;
		}
		if (cId[x][y] == -1) {
			return;
		}
		cnt[cId[x][y]]++;
		if (cnt[cId[x][y]] == 1) {
			sumSizes += sz[cId[x][y]];
		}
	}

	void rem(int x, int y) {
		if (x < 0 || x >= n || y < 0 || y >= n) {
			return;
		}
		if (cId[x][y] == -1) {
			return;
		}
		cnt[cId[x][y]]--;
		if (cnt[cId[x][y]] == 0) {
			sumSizes -= sz[cId[x][y]];
		}
	}

	int[] cnt;
	int[] sz;

	void run() {
		try {
			in = new FastScanner(new File("object.in"));
			out = new PrintWriter(new File("object.out"));

			solve();

			out.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	void runIO() {

		in = new FastScanner(System.in);
		out = new PrintWriter(System.out);

		solve();

		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		public FastScanner(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return null;
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		}

		boolean hasMoreTokens() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return false;
				st = new StringTokenizer(s);
			}
			return true;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}
	}

	public static void main(String[] args) {
		new CF().runIO();
	}
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ilyakor
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        static final int[] dx = new int[]{-1, 1, 0, 0};
        static final int[] dy = new int[]{0, 0, -1, 1};
        int n;
        int k;
        boolean[][] a;
        int[][] sum;
        int[][] sum2;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            n = in.nextInt();
            k = in.nextInt();
//        n = 500;
//        k = 150;
//        Random random = new Random(0xdead);

            TaskC.PersistentDSU dsu = new TaskC.PersistentDSU((n + 2) * (n + 2) + 1, n);
            int N = n + 2;
            int S = N * N;
            a = new boolean[n][n];
            for (int i = 0; i < n; ++i) {
                String s = in.nextToken();
                for (int j = 0; j < n; ++j)
                    a[i][j] = s.charAt(j) == '.';
//            for (int j = 0; j < n; ++j)
//                a[i][j] = random.nextInt(2) == 1;
            }

            sum = new int[n][n];
            for (int i = 0; i < n; ++i) {
                int cur = 0;
                for (int j = 0; j < n; ++j) {
                    cur += a[i][j] ? 0 : 1;
                    if (j - k >= 0) {
                        cur -= a[i][j - k] ? 0 : 1;
                    }
                    if (j - k + 1 >= 0) {
                        sum[i][j - k + 1] = cur;
                    }
                }
            }
            sum2 = new int[n][n];
            for (int i = 0; i < n; ++i) {
                int cur = 0;
                for (int j = 0; j < n; ++j) {
                    cur += sum[j][i];
                    if (j - k >= 0) {
                        cur -= sum[j - k][i];
                    }
                    if (j - k + 1 >= 0) {
                        sum2[j - k + 1][i] = cur;
                    }
                }
            }

            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < n; ++j) {
                    if (!a[i][j]) continue;
                    dsu.cnt[(i + 1) * N + j + 1] = 1;
                }
            }

            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < n; ++j) {
                    if (!a[i][j]) continue;
                    for (int dir = 0; dir < 4; ++dir) {
                        int x = i + dx[dir];
                        int y = j + dy[dir];
                        if (x >= 0 && x < n && y >= 0 && y < n && a[x][y])
                            dsu.unite((i + 1) * N + j + 1, (x + 1) * N + y + 1);
                    }
                }
            }
            int res = 0;
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < n; ++j) {
                    int r = dsu.root((i + 1) * N + j + 1);
                    res = Math.max(res, dsu.cnt[r]);
                }
            }

            int[] del = new int[(n + 2) * (n + 2) + 1];

            for (int i = 0; i <= n - k; ++i) {
                int internal = 0;
                for (int x = 0; x < k; ++x) {
                    for (int y = 0; y < k; ++y) {
                        int t = (i + x + 1) * N + (y + 1);
                        if (dsu.p[t] != t) continue;
                        int mx = dsu.mx[t];
                        int Mx = dsu.Mx[t];
                        int my = dsu.my[t];
                        int My = dsu.My[t];
                        if (mx >= i && Mx <= i + k - 1 && my >= 0 && My <= k - 1)
                            internal += dsu.cnt[t];
                    }
                }
                for (int j = 0; j <= n - k; ++j) {
                    dsu.reset();
                    if (j > 0) for (int x = 0; x < k; ++x) {
                        if (!a[i + x][j - 1]) continue;
                        if (x == 0 || !a[i + x - 1][j - 1])
                            dsu.punite(S, (i + x + 1) * N + j);
                    }
                    if (j + k < n) for (int x = 0; x < k; ++x) {
                        if (!a[i + x][j + k]) continue;
                        if (x == 0 || !a[i + x - 1][j + k])
                            dsu.punite(S, (i + x + 1) * N + j + k + 1);
                    }
                    if (i > 0) for (int x = 0; x < k; ++x) {
                        if (!a[i - 1][j + x]) continue;
                        if (x == 0 || !a[i - 1][j + x - 1])
                            dsu.punite(S, i * N + j + x + 1);
                    }
                    if (i + k < n) for (int x = 0; x < k; ++x) {
                        if (!a[i + k][j + x]) continue;
                        if (x == 0 || !a[i + k][j + x - 1])
                            dsu.punite(S, (i + k + 1) * N + j + x + 1);
                    }
                    int cur = sum2[i][j] + dsu.Cnt[dsu.proot(S)] + internal;
                    if (cur > res) res = cur;

                    int M = dsu.marker;
                    for (int y = 0; y < 2; ++y) {
                        for (int x = 0; x < k; ++x) {
                            if (j + y >= n || !a[i + x][j + y]) continue;
                            int t = (i + x + 1) * N + j + 1 + y;
                            t = dsu.p[t];
                            if (del[t] == M) continue;
                            del[t] = M;
                            int mx = dsu.mx[t];
                            int Mx = dsu.Mx[t];
                            int my = dsu.my[t];
                            int My = dsu.My[t];
                            if (mx >= i && Mx <= i + k - 1 && my >= j && My <= j + k - 1) {
                                if (!(mx >= i && Mx <= i + k - 1 && my >= j + 1 && My <= j + k)) {
                                    internal -= dsu.cnt[t];
                                }
                            }
                        }
                        for (int x = 0; x < k; ++x) {
                            if (j + k - y >= n || j + k - y < 0 || !a[i + x][j + k - y]) continue;
                            int t = (i + x + 1) * N + j + k + 1 - y;
                            t = dsu.p[t];
                            if (del[t] == M) continue;
                            del[t] = M;
                            int mx = dsu.mx[t];
                            int Mx = dsu.Mx[t];
                            int my = dsu.my[t];
                            int My = dsu.My[t];
                            if (!(mx >= i && Mx <= i + k - 1 && my >= j && My <= j + k - 1)) {
                                if ((mx >= i && Mx <= i + k - 1 && my >= j + 1 && My <= j + k)) {
                                    internal += dsu.cnt[t];
                                }
                            }
                        }
                    }
                }
            }
            out.printLine(res);
        }

        static class PersistentDSU {
            int[] p;
            int[] cnt;
            int[] Mx;
            int[] mx;
            int[] My;
            int[] my;
            int[] P;
            int[] Cnt;
            int[] u;
            int marker;
            int n;

            void init() {
                for (int i = 0; i < p.length; i++) {
                    p[i] = i;
                    cnt[i] = 0;
                    mx[i] = i / (n + 2) - 1;
                    my[i] = i % (n + 2) - 1;
                    Mx[i] = i / (n + 2) - 1;
                    My[i] = i % (n + 2) - 1;
                }
            }

            PersistentDSU(int size, int n) {
                this.n = n;
                p = new int[size];
                P = new int[size];
                mx = new int[size];
                Mx = new int[size];
                my = new int[size];
                My = new int[size];
                u = new int[size];
                cnt = new int[size];
                Cnt = new int[size];
                marker = 1;
                init();
            }

            void reset() {
                ++marker;
            }

            int root(int x) {
                if (x == p[x])
                    return x;
                return p[x] = root(p[x]);
            }

            void unite(int a, int b) {
                a = root(a);
                b = root(b);
                if (a == b)
                    return;
                //if (rnd.nextBoolean()) {
                if ((((a * 57 + b * 43) ^ (a * b + 12)) >> 3) % 2 == 0) {
                    p[a] = b;
                    cnt[b] += cnt[a];
                    if (mx[b] > mx[a]) mx[b] = mx[a];
                    if (my[b] > my[a]) my[b] = my[a];
                    if (Mx[b] < Mx[a]) Mx[b] = Mx[a];
                    if (My[b] < My[a]) My[b] = My[a];
                } else {
                    p[b] = a;
                    cnt[a] += cnt[b];
                    if (mx[a] > mx[b]) mx[a] = mx[b];
                    if (my[a] > my[b]) my[a] = my[b];
                    if (Mx[a] < Mx[b]) Mx[a] = Mx[b];
                    if (My[a] < My[b]) My[a] = My[b];
                }
            }

            int proot(int x) {
                if (u[x] != marker) {
                    u[x] = marker;
                    P[x] = p[x];
                    Cnt[x] = cnt[x];
                }
                if (x == P[x]) return x;
                return P[x] = proot(P[x]);
            }

            void punite(int a, int b) {
                a = proot(a);
                b = proot(b);
                if (a == b)
                    return;
                //if (rnd.nextBoolean()) {
                if ((((a * 57 + b * 43) ^ (a * b + 12)) >> 3) % 2 == 0) {
                    P[a] = b;
                    Cnt[b] += Cnt[a];
                } else {
                    P[b] = a;
                    u[b] = marker;
                    Cnt[a] += Cnt[b];
                }
            }

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void printLine(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buffer = new byte[10000];
        private int cur;
        private int count;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public static boolean isSpace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int read() {
            if (count == -1) {
                throw new InputMismatchException();
            }
            try {
                if (cur >= count) {
                    cur = 0;
                    count = stream.read(buffer);
                    if (count <= 0)
                        return -1;
                }
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            return buffer[cur++];
        }

        public int readSkipSpace() {
            int c;
            do {
                c = read();
            } while (isSpace(c));
            return c;
        }

        public String nextToken() {
            int c = readSkipSpace();
            StringBuilder sb = new StringBuilder();
            while (!isSpace(c)) {
                sb.append((char) c);
                c = read();
            }
            return sb.toString();
        }

        public int nextInt() {
            int sgn = 1;
            int c = readSkipSpace();
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res = res * 10 + c - '0';
                c = read();
            } while (!isSpace(c));
            res *= sgn;
            return res;
        }

    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 29);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            CBearAndSquareGrid solver = new CBearAndSquareGrid();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class CBearAndSquareGrid {
        boolean[][] visited;
        int k;
        int ans;
        int sum;
        int[] conn;
        int b;
        int t;
        int l;
        int r;
        int n;
        int[][] mat;
        int[][] cc;
        int[] size;
        int[][] ps;

        public void solve(int testNumber, FastInput in, FastOutput out) {
            n = in.readInt();
            k = in.readInt();
            mat = new int[n + 2][n + 2];
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= n; j++) {
                    mat[i][j] = in.readChar() == '.' ? 0 : 1;
                }
            }
            ps = new int[n + 2][n + 2];
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= n; j++) {
                    ps[i][j] = mat[i][j];
                    ps[i][j] += ps[i][j - 1];
                }
                for (int j = 1; j <= n; j++) {
                    ps[i][j] += ps[i - 1][j];
                }
            }

            cc = new int[n + 2][n + 2];
            size = new int[(n + 2) * (n + 2) + 1];
            SequenceUtils.deepFill(cc, 0);
            int order = 1;
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= n; j++) {
                    if (mat[i][j] == 0 && cc[i][j] == 0) {
                        size[order] = dfs(i, j, order);
                        order++;
                    }
                }
            }
            conn = new int[order];
            visited = new boolean[n + 2][n + 2];

            for (int i = 0; i <= k + 1; i++) {
                for (int j = 0; j <= k + 1; j++) {
                    add(i, j, 1);
                }
            }
            l = 0;
            r = k + 1;
            b = 0;
            t = k + 1;

            dfsForMove();

            out.println(ans);
        }

        public void dfsForMove() {
            visited[b][l] = true;
            update();
            if (t + 1 <= n + 1 && !visited[b + 1][l]) {
                moveDown();
            } else if (r + 1 <= n + 1 && !visited[b][l + 1]) {
                moveRight();
            } else if (b - 1 >= 0 && !visited[b - 1][l]) {
                moveUp();
            } else if (l - 1 >= 0 && !visited[b][l - 1]) {
                moveLeft();
            } else {
                return;
            }
            dfsForMove();
        }

        public void update() {
            add(b, l, -1);
            add(t, l, -1);
            add(b, r, -1);
            add(t, r, -1);

            int cand = sum + region(b + 1, t - 1, l + 1, r - 1);
            ans = Math.max(ans, cand);

            add(b, l, 1);
            add(t, l, 1);
            add(b, r, 1);
            add(t, r, 1);
        }

        public void moveDown() {
            for (int i = l; i <= r; i++) {
                add(b, i, -1);
                add(t + 1, i, 1);
            }
            b++;
            t++;
        }

        public void moveUp() {
            for (int i = l; i <= r; i++) {
                add(b - 1, i, 1);
                add(t, i, -1);
            }
            b--;
            t--;
        }

        public void moveRight() {
            for (int i = b; i <= t; i++) {
                add(i, l, -1);
                add(i, r + 1, 1);
            }
            l++;
            r++;
        }

        public void moveLeft() {
            for (int i = b; i <= t; i++) {
                add(i, l - 1, 1);
                add(i, r, -1);
            }
            l--;
            r--;
        }

        public boolean check(int i, int j) {
            return !(i < 1 || j < 1 || i > n || j > n);
        }

        public void add(int i, int j, int x) {
            int id = cc[i][j];
            if (conn[id] == 0) {
                sum += size[id];
            }
            conn[id] += x;
            if (conn[id] == 0) {
                sum -= size[id];
            }
        }

        public int region(int b, int t, int l, int r) {
            int ans = ps[t][r];
            if (l > 0) {
                ans -= ps[t][l - 1];
            }
            if (b > 0) {
                ans -= ps[b - 1][r];
            }
            if (l > 0 && b > 0) {
                ans += ps[b - 1][l - 1];
            }
            return ans;
        }

        public int dfs(int i, int j, int id) {
            if (!check(i, j) || mat[i][j] == 1 || cc[i][j] != 0) {
                return 0;
            }
            cc[i][j] = id;
            return dfs(i + 1, j, id) + dfs(i - 1, j, id) + dfs(i, j - 1, id) + dfs(i, j + 1, id) + 1;
        }

    }

    static class FastOutput implements AutoCloseable, Closeable, Appendable {
        private StringBuilder cache = new StringBuilder(10 << 20);
        private final Writer os;

        public FastOutput append(CharSequence csq) {
            cache.append(csq);
            return this;
        }

        public FastOutput append(CharSequence csq, int start, int end) {
            cache.append(csq, start, end);
            return this;
        }

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput append(char c) {
            cache.append(c);
            return this;
        }

        public FastOutput append(int c) {
            cache.append(c);
            return this;
        }

        public FastOutput println(int c) {
            return append(c).println();
        }

        public FastOutput println() {
            cache.append(System.lineSeparator());
            return this;
        }

        public FastOutput flush() {
            try {
                os.append(cache);
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }

    static class SequenceUtils {
        public static void deepFill(Object array, int val) {
            if (!array.getClass().isArray()) {
                throw new IllegalArgumentException();
            }
            if (array instanceof int[]) {
                int[] intArray = (int[]) array;
                Arrays.fill(intArray, val);
            } else {
                Object[] objArray = (Object[]) array;
                for (Object obj : objArray) {
                    deepFill(obj, val);
                }
            }
        }

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

        public char readChar() {
            skipBlank();
            char c = (char) next;
            next = read();
            return c;
        }

    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BearAndSquareGrid solver = new BearAndSquareGrid();
        solver.solve(1, in, out);
        out.close();
    }

    static class BearAndSquareGrid {
        ArrayList<Integer>[][] connected = new ArrayList[502][502];
        int[] sz = new int[500 * 500 + 5];
        int[] active = new int[500 * 500 + 5];
        int res = 0;
        int K;
        int N;
        boolean[][] blocked;
        boolean[][] visited = new boolean[502][502];
        int[][] component = new int[502][502];
        int count = 1;
        int[] moveR = new int[]{-1, 0, 1, 0};
        int[] moveC = new int[]{0, 1, 0, -1};

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            N = in.nextInt();
            K = in.nextInt();
            blocked = new boolean[N + 2][N + 2];
            for (int i = 1; i <= N; i++) {
                char[] row = in.next().toCharArray();
                for (int j = 1; j <= N; j++) {
                    blocked[i][j] = (row[j - 1] == 'X');
                }
            }
            for (int i = 0; i <= N + 1; i++) {
                for (int j = 0; j <= N + 1; j++) {
                    if (i == 0 || j == 0 || j == N + 1 || i == N + 1) {
                        blocked[i][j] = true;
                    }
                }
            }
            for (int i = 1; i <= N; i++) {
                for (int j = 1; j <= N; j++) {
                    if (!visited[i][j] && !blocked[i][j]) {
                        floodFill(i, j);
                        count++;
                    }
                }
            }
            for (int i = 1; i <= N; i++) {
                for (int j = 1; j <= N; j++) {
                    connected[i][j] = new ArrayList<>();
                    if (!blocked[i][j]) {
                        connected[i][j].add(component[i][j]);
                    } else {
                        for (int m = 0; m < 4; m++) {
                            if (!blocked[i + moveR[m]][j + moveC[m]]) {
                                connected[i][j].add(component[i + moveR[m]][j + moveC[m]]);
                            }
                        }
                    }
                }
            }
            for (int i = 1; i <= K; i++) {
                rowK(1, i, false);
            }
            int ans = res;
            int curR = K;
            int curC = K;
            while (curR <= N) {
                if (curC == K) {
                    while (curC + 1 <= N) {
                        colK(curR - K + 1, curC - K + 1, true);
                        curC++;
                        colK(curR - K + 1, curC, false);
                        ans = Math.max(ans, res);
                    }
                } else if (curC == N) {
                    while (curC - 1 >= K) {
                        colK(curR - K + 1, curC, true);
                        curC--;
                        colK(curR - K + 1, curC - K + 1, false);
                        ans = Math.max(ans, res);
                    }
                }
                if (curR + 1 <= N) {
                    rowK(curC - K + 1, curR - K + 1, true);
                    curR++;
                    rowK(curC - K + 1, curR, false);
                    ans = Math.max(ans, res);
                } else {
                    break;
                }
            }
            out.println(ans);
        }

        void colK(int startRow, int col, boolean rem) {
            //add kValues starting from [startRow] at the col'th column
            for (int i = startRow; i <= startRow + K - 1; i++) {
                if (blocked[i][col]) {
                    if (rem) {
                        res--;
                    } else {
                        res++;
                    }
                }
                for (int c : connected[i][col]) {
                    if (rem) {
                        remove(c);
                    } else {
                        add(c);
                    }
                }
            }
        }

        void rowK(int startCol, int row, boolean rem) {
            for (int j = startCol; j <= startCol + K - 1; j++) {
                if (blocked[row][j]) {
                    if (rem) {
                        res--;
                    } else {
                        res++;
                    }
                }
                for (int c : connected[row][j]) {
                    if (rem) {
                        remove(c);
                    } else {
                        add(c);
                    }
                }
            }
        }

        void add(int comp) {
            active[comp]++;
            if (active[comp] == 1) {
                res += sz[comp];
            }
        }

        void remove(int comp) {
            active[comp]--;
            if (active[comp] == 0) {
                res -= sz[comp];
            }
        }

        void floodFill(int r, int c) {
            visited[r][c] = true;
            component[r][c] = count;
            sz[count]++;
            for (int i = 0; i < 4; i++) {
                if (!visited[r + moveR[i]][c + moveC[i]] && !blocked[r + moveR[i]][c + moveC[i]]) {
                    floodFill(r + moveR[i], c + moveC[i]);
                }
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class ProblemC2 {
    private static final Integer ONE = 1;
    BufferedReader rd;
    int[] inside;
    int[] size;
    int n, k;
    int res;
    char[][] c;
    int[][] idOf;
    int[] used;
    int u;

    ProblemC2() throws IOException {
        rd = new BufferedReader(new InputStreamReader(System.in));
        compute();
    }

    private void compute() throws IOException {
        int[] a = intarr();
        n = a[0];
        k = a[1];
        if(k == n) {
            res = n*n;
        } else {
            c = new char[n][];
            for (int i = 0; i < n; i++) {
                c[i] = rd.readLine().toCharArray();
            }
            idOf = new int[n][n];
            size = new int[250000];
            boolean[][] vis = new boolean[n][n];
            int[] cx = new int[]{-1, 1, 0, 0};
            int[] cy = new int[]{0, 0, -1, 1};
            Queue<Pair> q = new ArrayDeque<>();
            int maxId = 1;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if (!vis[i][j] && c[i][j] == '.') {
                        Set<Pair> pts = new HashSet<>();
                        q.add(new Pair(i, j));
                        while (!q.isEmpty()) {
                            Pair p = q.poll();
                            pts.add(p);
                            for (int m = 0; m < 4; m++) {
                                int g = p.v[0] + cx[m];
                                int h = p.v[1] + cy[m];
                                if (g >= 0 && g < n && h >= 0 && h < n) {
                                    if (!vis[g][h] && c[g][h] == '.') {
                                        vis[g][h] = true;
                                        q.add(new Pair(g, h));
                                    }
                                }
                            }
                        }
                        size[maxId] = pts.size();
                        for (Pair p : pts) {
                            idOf[p.v[0]][p.v[1]] = maxId;
                        }
                        maxId++;
                    }
                }
            }
            inside = new int[maxId];
            used = new int[maxId];
            for (int i = 0; i < k; i++) {
                for (int j = 0; j < k; j++) {
                    if (c[i][j] == '.') {
                        inside[idOf[i][j]]++;
                    }
                }
            }

            computeSize(0,0);

            int z = n - k;
            for (int i = 0; i <= z; i++) {
                for (int j = 0; j < z; j++) {
                    if (i % 2 == 0) {
                        updateInside(i, j + k, 1, 0, 1);
                        updateInside(i, j, 1, 0, -1);
                        computeSize(i,j+1);
                    } else {
                        updateInside(i, n - j - k - 1, 1, 0, 1);
                        updateInside(i, n - j - 1, 1, 0, -1);
                        computeSize(i,z-j-1);
                    }
                }
                if (i < z) {
                    if (i % 2 == 0) {
                        updateInside(i, z, 0, 1, -1);
                        updateInside(i + k, z, 0, 1, 1);
                        computeSize(i+1,z);
                    } else {
                        updateInside(i, 0, 0, 1, -1);
                        updateInside(i + k, 0, 0, 1, 1);
                        computeSize(i+1,0);
                    }
                }
            }
        }
        out(res);
    }

    private int updateTouch(int x, int y, int zx, int zy, int count) {
        int res = 0;
        for(int j=0;j<count;j++) {
            if(x >= 0 && x < n && y >= 0 && y < n) {
                if(c[x][y] == '.') {
                    int id = idOf[x][y];
                    if(used[id] < u) {
                        used[id] = u;
                        res += size[id] - inside[id];
                    }
                }
            } else {
                break;
            }
            x += zx;
            y += zy;
        }
        return res;
    }

    private void updateInside(int x, int y, int zx, int zy, int diff) {
        for(int j=0;j<k;j++) {
            if (c[x][y] == '.') {
                inside[idOf[x][y]] += diff;
            }
            x += zx;
            y += zy;
        }
    }

    private void computeSize(int i, int j) {
        u++;
        int max = k*k;
        max += updateTouch(i-1, j, 0, 1, k);
        max += updateTouch(i, j-1, 1, 0, k);
        max += updateTouch(i, j+k, 1, 0, k);
        max += updateTouch(i+k, j, 0, 1, k);
        res = Math.max(res, max);
    }

    class Pair {
        final int[] v;

        Pair(int a, int b) {
            v = new int[] { a, b };
        }

        Pair(int[] x) {
            v = x;
        }

        public boolean equals(Object o) {
            if (this == o) return true;
            if (o instanceof Pair) {
                return Arrays.equals(v, ((Pair) o).v);
            }
            return false;
        }

        public int hashCode() {
            return v != null ? Arrays.hashCode(v) : 0;
        }

        public String toString() {
            return Arrays.toString(v);
        }
    }

    private int[] intarr() throws IOException {
        return intarr(rd.readLine());
    }

    private int[] intarr(String s) {
        String[] q = split(s);
        int n = q.length;
        int[] a = new int[n];
        for(int i=0;i<n;i++) {
            a[i] = Integer.parseInt(q[i]);
        }
        return a;
    }

    public String[] split(String s) {
        if(s == null) {
            return new String[0];
        }
        int n = s.length();
        int start = -1;
        int end = 0;
        int sp = 0;
        boolean lastWhitespace = true;
        for(int i=0;i<n;i++) {
            char c = s.charAt(i);
            if(isWhitespace(c)) {
                lastWhitespace = true;
            } else {
                if(lastWhitespace) {
                    sp++;
                }
                if(start == -1) {
                    start = i;
                }
                end = i;
                lastWhitespace = false;
            }
        }
        if(start == -1) {
            return new String[0];
        }
        String[] res = new String[sp];
        int last = start;
        int x = 0;
        lastWhitespace = true;
        for(int i=start;i<=end;i++) {
            char c = s.charAt(i);
            boolean w = isWhitespace(c);
            if(w && !lastWhitespace) {
                res[x++] = s.substring(last,i);
            } else if(!w && lastWhitespace) {
                last = i;
            }
            lastWhitespace = w;
        }
        res[x] = s.substring(last,end+1);
        return res;
    }

    private boolean isWhitespace(char c) {
        return c==' ' || c=='\t';
    }

    private static void out(Object x) {
        System.out.println(x);
    }

    public static void main(String[] args) throws IOException {
        new ProblemC2();
    }
}

import sun.awt.image.ImageWatched;

import java.io.*;
import java.util.ArrayDeque;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.LinkedList;

public class Cf0806E {
    private static InputReader in = new InputReader(System.in);
    private static OutputWriter out = new OutputWriter(System.out);
    private static int n,k;
    private static int[][] grid;
    private static int component;
    private static int[][] cc;

    private static void dfs(int x, int y){
        if((x==-1||x==n||y==-1||y==n)||(cc[x][y]!=0)||(grid[x][y]==0)){
            return;
        }
        cc[x][y] = component;
        dfs(x+1,y);
        dfs(x-1,y);
        dfs(x,y+1);
        dfs(x,y-1);
    }

    private static void solve() throws Exception{
        n = in.readInt();
        k = in.readInt();
        grid = new int[n][n];
        cc = new int[n][n];
        for(int i=0; i<n; ++i){
            String s = in.readString();
            for(int j=0; j<n; ++j){
                if(s.charAt(j)=='.'){
                    grid[i][j] = 1;
                }
            }
        }
        for(int i=0; i<n; ++i){
            for(int j=0; j<n; ++j){
                if((cc[i][j]!=0)||(grid[i][j]==0)){
                    continue;
                }
                component++;
                dfs(i,j);
            }
        }
        int[] totalCount = new int[component+1];
        for(int i=0; i<n; ++i){
            for(int j=0; j<n;++j){
                totalCount[cc[i][j]]++;
            }
        }

        int answer = 0;
        boolean[] marked = new boolean[component+1];
        ArrayDeque<Integer> ccList = new ArrayDeque<>();
        for(int i=0; i<=n-k;++i){
            int[] count = new int[component+1];
            for(int z=i; z<i+k; ++z) {
                for (int j = 0; j < k - 1; ++j) {
                    if(cc[z][j]!=0) {
                        count[cc[z][j]]++;
                    }
                }
            }
            for(int j=k-1; j<n; ++j) {
                for(int z=i; z<i+k; ++z) {
                    if(cc[z][j]!=0) {
                        count[cc[z][j]]++;
                    }
                }

                if(j!=n-1){
                    for(int z=i; z<i+k; ++z){
                        if(cc[z][j+1]==0){
                            continue;
                        }
                        if(marked[cc[z][j+1]]){
                            continue;
                        }
                        marked[cc[z][j+1]] = true;
                        ccList.add(cc[z][j+1]);
                    }
                }
                if(j!=k-1){
                    for(int z=i; z<i+k; ++z){
                        if(cc[z][j-k]==0){
                            continue;
                        }
                        if(marked[cc[z][j-k]]){
                            continue;
                        }
                        marked[cc[z][j-k]] = true;
                        ccList.add(cc[z][j-k]);
                    }
                }
                if(i!=0){
                    for(int z=j-k+1;z<=j; ++z){
                        if(cc[i-1][z]==0){
                            continue;
                        }
                        if(marked[cc[i-1][z]]){
                            continue;
                        }
                        marked[cc[i-1][z]] = true;
                        ccList.add(cc[i-1][z]);

                    }
                }
                if(i!=n-k){
                    for(int z=j-k+1;z<=j; ++z){
                        if(cc[i+k][z]==0){
                            continue;
                        }
                        if(marked[cc[i+k][z]]){
                            continue;
                        }
                        marked[cc[i+k][z]]= true;
                        ccList.add(cc[i+k][z]);
                    }
                }
                int result = k*k;
                while(!ccList.isEmpty()){
                    int item = ccList.pop();
                    result += (totalCount[item]-count[item]);
                    marked[item] = false;
                }

                answer = Math.max(answer,result);
                for(int z=i; z<i+k; ++z){
                    if(cc[z][j-k+1]!=0) {
                        count[cc[z][j - k + 1]]--;
                    }
                }
            }
        }
        out.println(answer);

    }

    public static void main(String[] args) throws Exception {
        solve();
        out.close();
    }

    private static class InputReader {
        private InputStream stream;
        private byte[] buffer;
        private int currentIndex;
        private int bytesRead;

        public InputReader(InputStream stream) {
            this.stream = stream;
            buffer = new byte[131072];
        }

        public InputReader(InputStream stream, int bufferSize) {
            this.stream = stream;
            buffer = new byte[bufferSize];
        }

        private int read() throws IOException {
            if (currentIndex >= bytesRead) {
                currentIndex = 0;
                bytesRead = stream.read(buffer);
                if (bytesRead <= 0) {
                    return -1;
                }
            }
            return buffer[currentIndex++];
        }

        public String readString() throws IOException {
            int c = read();
            while (!isPrintable(c)) {
                c = read();
            }
            StringBuilder result = new StringBuilder();
            do {
                result.appendCodePoint(c);
                c = read();
            } while (isPrintable(c));
            return result.toString();
        }

        public int readInt() throws Exception {
            int c = read();
            int sign = 1;
            while (!isPrintable(c)) {
                c = read();
            }
            if (c == '-') {
                sign = -1;
                c = read();
            }
            int result = 0;
            do {
                if ((c < '0') || (c > '9')) {
                    throw new InputMismatchException();
                }
                result *= 10;
                result += (c - '0');
                c = read();
            } while (isPrintable(c));
            return sign * result;
        }

        public long readLong() throws Exception {
            int c = read();
            int sign = 1;
            while (!isPrintable(c)) {
                c = read();
            }
            if (c == '-') {
                sign = -1;
                c = read();
            }
            long result = 0;
            do {
                if ((c < '0') || (c > '9')) {
                    throw new InputMismatchException();
                }
                result *= 10;
                result += (c - '0');
                c = read();
            } while (isPrintable(c));
            return sign * result;
        }

        public double readDouble() throws Exception {
            int c = read();
            int sign = 1;
            while (!isPrintable(c)) {
                c = read();
            }
            if (c == '-') {
                sign = -1;
                c = read();
            }
            boolean fraction = false;
            double multiplier = 1;
            double result = 0;
            do {
                if ((c == 'e') || (c == 'E')) {
                    return sign * result * Math.pow(10, readInt());
                }
                if ((c < '0') || (c > '9')) {
                    if ((c == '.') && (!fraction)) {
                        fraction = true;
                        c = read();
                        continue;
                    }
                    throw new InputMismatchException();
                }
                if (fraction) {
                    multiplier /= 10;
                    result += (c - '0') * multiplier;
                    c = read();
                } else {
                    result *= 10;
                    result += (c - '0');
                    c = read();
                }
            } while (isPrintable(c));
            return sign * result;
        }

        private boolean isPrintable(int c) {
            return ((c > 32) && (c < 127));
        }
    }

    private static class OutputWriter {
        private PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

        public void flush() {
            writer.flush();
        }
    }
}

import sun.awt.image.ImageWatched;

import java.io.*;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.LinkedList;

public class Cf0806E {
    private static InputReader in = new InputReader(System.in);
    private static OutputWriter out = new OutputWriter(System.out);
    private static int n,k;
    private static int[][] grid;
    private static int component;
    private static int[][] cc;

    private static void dfs(int x, int y){
        if((x==-1||x==n||y==-1||y==n)||(cc[x][y]!=0)||(grid[x][y]==0)){
            return;
        }
        cc[x][y] = component;
        dfs(x+1,y);
        dfs(x-1,y);
        dfs(x,y+1);
        dfs(x,y-1);
    }

    private static void solve() throws Exception{
        n = in.readInt();
        k = in.readInt();
        grid = new int[n][n];
        cc = new int[n][n];
        for(int i=0; i<n; ++i){
            String s = in.readString();
            for(int j=0; j<n; ++j){
                if(s.charAt(j)=='.'){
                    grid[i][j] = 1;
                }
            }
        }
        for(int i=0; i<n; ++i){
            for(int j=0; j<n; ++j){
                if((cc[i][j]!=0)||(grid[i][j]==0)){
                    continue;
                }
                component++;
                dfs(i,j);
            }
        }
        int[] totalCount = new int[component+1];
        for(int i=0; i<n; ++i){
            for(int j=0; j<n;++j){
                totalCount[cc[i][j]]++;
            }
        }

        int answer = 0;
        boolean[] marked = new boolean[component+1];
        for(int i=0; i<=n-k;++i){
            int[] count = new int[component+1];
            for(int z=i; z<i+k; ++z) {
                for (int j = 0; j < k - 1; ++j) {
                    count[cc[z][j]]++;
                }
            }
            for(int j=k-1; j<n; ++j) {
                for(int z=i; z<i+k; ++z) {
                    count[cc[z][j]]++;
                }

                LinkedList<Integer> ccList = new LinkedList<>();

                if(j!=n-1){
                    for(int z=i; z<i+k; ++z){
                        if(cc[z][j+1]==0){
                            continue;
                        }
                        if(marked[cc[z][j+1]]){
                            continue;
                        }
                        marked[cc[z][j+1]] = true;
                        ccList.add(cc[z][j+1]);
                    }
                }
                if(j!=k-1){
                    for(int z=i; z<i+k; ++z){
                        if(cc[z][j-k]==0){
                            continue;
                        }
                        if(marked[cc[z][j-k]]){
                            continue;
                        }
                        marked[cc[z][j-k]] = true;
                        ccList.add(cc[z][j-k]);
                    }
                }
                if(i!=0){
                    for(int z=j-k+1;z<=j; ++z){
                        if(cc[i-1][z]==0){
                            continue;
                        }
                        if(marked[cc[i-1][z]]){
                            continue;
                        }
                        marked[cc[i-1][z]] = true;
                        ccList.add(cc[i-1][z]);

                    }
                }
                if(i!=n-k){
                    for(int z=j-k+1;z<=j; ++z){
                        if(cc[i+k][z]==0){
                            continue;
                        }
                        if(marked[cc[i+k][z]]){
                            continue;
                        }
                        marked[cc[i+k][z]]= true;
                        ccList.add(cc[i+k][z]);
                    }
                }
                int result = k*k;
                for(Integer item: ccList){
                    result += (totalCount[item]-count[item]);
                    marked[item] = false;
                }

                answer = Math.max(answer,result);
                for(int z=i; z<i+k; ++z){
                    count[cc[z][j-k+1]]--;
                }
            }
        }
        out.println(answer);

    }

    public static void main(String[] args) throws Exception {
        solve();
        out.close();
    }

    private static class InputReader {
        private InputStream stream;
        private byte[] buffer;
        private int currentIndex;
        private int bytesRead;

        public InputReader(InputStream stream) {
            this.stream = stream;
            buffer = new byte[131072];
        }

        public InputReader(InputStream stream, int bufferSize) {
            this.stream = stream;
            buffer = new byte[bufferSize];
        }

        private int read() throws IOException {
            if (currentIndex >= bytesRead) {
                currentIndex = 0;
                bytesRead = stream.read(buffer);
                if (bytesRead <= 0) {
                    return -1;
                }
            }
            return buffer[currentIndex++];
        }

        public String readString() throws IOException {
            int c = read();
            while (!isPrintable(c)) {
                c = read();
            }
            StringBuilder result = new StringBuilder();
            do {
                result.appendCodePoint(c);
                c = read();
            } while (isPrintable(c));
            return result.toString();
        }

        public int readInt() throws Exception {
            int c = read();
            int sign = 1;
            while (!isPrintable(c)) {
                c = read();
            }
            if (c == '-') {
                sign = -1;
                c = read();
            }
            int result = 0;
            do {
                if ((c < '0') || (c > '9')) {
                    throw new InputMismatchException();
                }
                result *= 10;
                result += (c - '0');
                c = read();
            } while (isPrintable(c));
            return sign * result;
        }

        public long readLong() throws Exception {
            int c = read();
            int sign = 1;
            while (!isPrintable(c)) {
                c = read();
            }
            if (c == '-') {
                sign = -1;
                c = read();
            }
            long result = 0;
            do {
                if ((c < '0') || (c > '9')) {
                    throw new InputMismatchException();
                }
                result *= 10;
                result += (c - '0');
                c = read();
            } while (isPrintable(c));
            return sign * result;
        }

        public double readDouble() throws Exception {
            int c = read();
            int sign = 1;
            while (!isPrintable(c)) {
                c = read();
            }
            if (c == '-') {
                sign = -1;
                c = read();
            }
            boolean fraction = false;
            double multiplier = 1;
            double result = 0;
            do {
                if ((c == 'e') || (c == 'E')) {
                    return sign * result * Math.pow(10, readInt());
                }
                if ((c < '0') || (c > '9')) {
                    if ((c == '.') && (!fraction)) {
                        fraction = true;
                        c = read();
                        continue;
                    }
                    throw new InputMismatchException();
                }
                if (fraction) {
                    multiplier /= 10;
                    result += (c - '0') * multiplier;
                    c = read();
                } else {
                    result *= 10;
                    result += (c - '0');
                    c = read();
                }
            } while (isPrintable(c));
            return sign * result;
        }

        private boolean isPrintable(int c) {
            return ((c > 32) && (c < 127));
        }
    }

    private static class OutputWriter {
        private PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

        public void flush() {
            writer.flush();
        }
    }
}

import sun.awt.image.ImageWatched;

import java.io.*;
import java.util.ArrayDeque;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.LinkedList;

public class Cf0806E {
    private static InputReader in = new InputReader(System.in);
    private static OutputWriter out = new OutputWriter(System.out);
    private static int n,k;
    private static int[][] grid;
    private static int component;
    private static int[][] cc;
    private static int[][] dp;
    private static int currentSum;
    private static int[] mark;
    private static int[] totalCount;

    private static void dfs(int x, int y){
        if((x==-1||x==n||y==-1||y==n)||(cc[x][y]!=0)||(grid[x][y]==0)){
            return;
        }
        cc[x][y] = component;
        dfs(x+1,y);
        dfs(x-1,y);
        dfs(x,y+1);
        dfs(x,y-1);
    }

    private static void solve() throws Exception{
        n = in.readInt();
        k = in.readInt();
        grid = new int[n][n];
        cc  =  new int[n][n];
        dp  = new int[n][n];

        for(int i=0; i<n; ++i){
            String s = in.readString();
            for(int j=0; j<n; ++j){
                if(i!=0) {
                    dp[i][j] += dp[i - 1][j];
                }
                if(j!=0) {
                    dp[i][j] += dp[i][j - 1];
                }
                if((i!=0)&&(j!=0)){
                    dp[i][j] -= dp[i-1][j-1];
                }
                if(s.charAt(j)=='.'){
                    grid[i][j] = 1;
                }
                else{
                    dp[i][j]++;
                }

            }
        }
        for(int i=0; i<n; ++i){
            for(int j=0; j<n; ++j){
                if((cc[i][j]!=0)||(grid[i][j]==0)){
                    continue;
                }
                component++;
                dfs(i,j);
            }
        }
        totalCount = new int[component+1];
        for(int i=0; i<n; ++i){
            for(int j=0; j<n;++j){
                totalCount[cc[i][j]]++;
            }
        }

        int answer = 0;
        for(int i=0; i<=n-k;++i) {
            currentSum = 0;
            mark = new int[component+1];
            for(int z=i-1;z<=i+k;++z){
                for(int j=0; j<k; ++j){
                    add(z,j);
                }
            }
            for(int j=k-1; j<n; ++j){
                for(int z=i; z<i+k; ++z) {
                    add(z, j + 1);
                }
                int result = dp[i+k-1][j];
                if((j!=k-1)&&(i!=0)){
                    result += dp[i-1][j-k];
                }
                if(j!=k-1){
                    result -= dp[i+k-1][j-k];
                }
                if(i!=0){
                    result -= dp[i-1][j];
                }
                result += currentSum;
                answer = Math.max(answer,result);
                for(int z=i; z<i+k;++z){
                    remove(z,j-k);
                }
                remove(i-1,j-k+1);
                remove(i+k,j-k+1);
                add(i-1,j+1);
                add(i+k,j+1);
            }
        }
        out.println(answer);
    }

    private static void add(int x, int y){
        if((x==-1||x==n||y==-1||y==n)||(grid[x][y]==0)){
            return;
        }
        mark[cc[x][y]]++;
        if(mark[cc[x][y]]==1){
            currentSum += totalCount[cc[x][y]];
        }
    }

    private static void remove(int x, int y){
        if((x==-1||x==n||y==-1||y==n)||(grid[x][y]==0)){
            return;
        }
        mark[cc[x][y]]--;
        if(mark[cc[x][y]]==0){
            currentSum -= totalCount[cc[x][y]];
        }
    }

    public static void main(String[] args) throws Exception {
        solve();
        out.close();
    }

    private static class InputReader {
        private InputStream stream;
        private byte[] buffer;
        private int currentIndex;
        private int bytesRead;

        public InputReader(InputStream stream) {
            this.stream = stream;
            buffer = new byte[131072];
        }

        public InputReader(InputStream stream, int bufferSize) {
            this.stream = stream;
            buffer = new byte[bufferSize];
        }

        private int read() throws IOException {
            if (currentIndex >= bytesRead) {
                currentIndex = 0;
                bytesRead = stream.read(buffer);
                if (bytesRead <= 0) {
                    return -1;
                }
            }
            return buffer[currentIndex++];
        }

        public String readString() throws IOException {
            int c = read();
            while (!isPrintable(c)) {
                c = read();
            }
            StringBuilder result = new StringBuilder();
            do {
                result.appendCodePoint(c);
                c = read();
            } while (isPrintable(c));
            return result.toString();
        }

        public int readInt() throws Exception {
            int c = read();
            int sign = 1;
            while (!isPrintable(c)) {
                c = read();
            }
            if (c == '-') {
                sign = -1;
                c = read();
            }
            int result = 0;
            do {
                if ((c < '0') || (c > '9')) {
                    throw new InputMismatchException();
                }
                result *= 10;
                result += (c - '0');
                c = read();
            } while (isPrintable(c));
            return sign * result;
        }

        public long readLong() throws Exception {
            int c = read();
            int sign = 1;
            while (!isPrintable(c)) {
                c = read();
            }
            if (c == '-') {
                sign = -1;
                c = read();
            }
            long result = 0;
            do {
                if ((c < '0') || (c > '9')) {
                    throw new InputMismatchException();
                }
                result *= 10;
                result += (c - '0');
                c = read();
            } while (isPrintable(c));
            return sign * result;
        }

        public double readDouble() throws Exception {
            int c = read();
            int sign = 1;
            while (!isPrintable(c)) {
                c = read();
            }
            if (c == '-') {
                sign = -1;
                c = read();
            }
            boolean fraction = false;
            double multiplier = 1;
            double result = 0;
            do {
                if ((c == 'e') || (c == 'E')) {
                    return sign * result * Math.pow(10, readInt());
                }
                if ((c < '0') || (c > '9')) {
                    if ((c == '.') && (!fraction)) {
                        fraction = true;
                        c = read();
                        continue;
                    }
                    throw new InputMismatchException();
                }
                if (fraction) {
                    multiplier /= 10;
                    result += (c - '0') * multiplier;
                    c = read();
                } else {
                    result *= 10;
                    result += (c - '0');
                    c = read();
                }
            } while (isPrintable(c));
            return sign * result;
        }

        private boolean isPrintable(int c) {
            return ((c > 32) && (c < 127));
        }
    }

    private static class OutputWriter {
        private PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

        public void flush() {
            writer.flush();
        }
    }
}

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 * #
 * @author pttrung
 */
public class C_Round_356_Div1 {

    public static long MOD = 1000000007;
    static int[] X = {0, 1, 0, -1};
    static int[] Y = {1, 0, -1, 0};

    public static void main(String[] args) throws FileNotFoundException {
        // PrintWriter out = new PrintWriter(new FileOutputStream(new File(
        // "output.txt")));
        PrintWriter out = new PrintWriter(System.out);
        Scanner in = new Scanner();
        int n = in.nextInt();
        int k = in.nextInt();
        if (n == k) {
            out.println(n * n);
        } else {
            String[] data = new String[n];
            int[][] com = new int[n][n];
            for (int i = 0; i < n; i++) {
                data[i] = in.next();
            }
            int cur = 1;
            int[] list = new int[n * n + 1];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {

                    if (data[i].charAt(j) == '.') {
                        if (com[i][j] == 0) {
                            LinkedList<Point> q = new LinkedList();
                            q.add(new Point(i, j));
                            com[i][j] = cur;
                            int count = 1;
                            while (!q.isEmpty()) {
                                Point p = q.poll();
                                for (int h = 0; h < 4; h++) {
                                    int x = p.x + X[h];
                                    int y = p.y + Y[h];
                                    if (x >= 0 && x < n && y >= 0 && y < n && com[x][y] == 0 && data[x].charAt(y) == '.') {
                                        com[x][y] = cur;
                                        count++;
                                        q.add(new Point(x, y));
                                    }
                                }
                            }
                            list[cur] = count;
                            cur++;
                        }
                    }
                }
            }
//            for (int[] a : com) {
//                System.out.println(Arrays.toString(a));
//            }
            int[] track = new int[cur];
            int result = 0;
            int index = 0;
            int start = 0;
            int add = 1;
            for (int i = 0; i < k; i++) {
                for (int j = 0; j < k; j++) {
                    list[com[i][j]]--;
                }
            }
            for (int i = 0; i + k <= n; i++) {
                for (int j = start; j + k <= n && j >= 0; j += add) {
                    index++;
                    int tmp = 0;

                    if (i > 0) {
                        for (int h = 0; h < k; h++) {
                            if (com[i - 1][j + h] != 0 && track[com[i - 1][j + h]] != index) {
                                track[com[i - 1][j + h]] = index;
                                tmp += list[com[i - 1][j + h]];
                            }
                        }
                    }
                    if (i + k < n) {
                        for (int h = 0; h < k; h++) {
                            if (com[i + k][j + h] != 0 && track[com[i + k][j + h]] != index) {
                                track[com[i + k][j + h]] = index;
                                tmp += list[com[i + k][j + h]];
                            }
                        }
                    }
                    if (j > 0) {
                        for (int h = 0; h < k; h++) {
                            if (com[i + h][j - 1] != 0 && track[com[i + h][j - 1]] != index) {
                                track[com[i + h][j - 1]] = index;
                                tmp += list[com[i + h][j - 1]];
                            }
                        }
                    }
                    if (j + k < n) {
                        for (int h = 0; h < k; h++) {
                            if (com[i + h][j + k] != 0 && track[com[i + h][j + k]] != index) {
                                track[com[i + h][j + k]] = index;
                                tmp += list[com[i + h][j + k]];
                            }
                        }
                    }

                    tmp += k * k;
                  //  System.out.println(tmp + " " + i + " " + j + " " + Arrays.toString(track));
                    result = Integer.max(result, tmp);
                    if (j + add + k <= n && j + add >= 0) {
                        for (int h = 0; h < k; h++) {
                            if (add == 1) {
                                list[com[i + h][j]]++;
                                list[com[i + h][j + k]]--;
                            } else {
                                list[com[i + h][j + k - 1]]++;
                                list[com[i + h][j - 1]]--;
                            }
                        }
                    }
                }
                add *= -1;
                start = n - k - start;
                if (i + k + 1 <= n) {
                    for (int h = 0; h < k; h++) {
                        list[com[i][h + start]]++;
                        list[com[i + k][h + start]]--;
                    }
                }
            }

            out.println(result);
        }
        out.close();
    }

    public static int[] KMP(String val) {
        int i = 0;
        int j = -1;
        int[] result = new int[val.length() + 1];
        result[0] = -1;
        while (i < val.length()) {
            while (j >= 0 && val.charAt(j) != val.charAt(i)) {
                j = result[j];
            }
            j++;
            i++;
            result[i] = j;
        }
        return result;

    }

    public static boolean nextPer(int[] data) {
        int i = data.length - 1;
        while (i > 0 && data[i] < data[i - 1]) {
            i--;
        }
        if (i == 0) {
            return false;
        }
        int j = data.length - 1;
        while (data[j] < data[i - 1]) {
            j--;
        }
        int temp = data[i - 1];
        data[i - 1] = data[j];
        data[j] = temp;
        Arrays.sort(data, i, data.length);
        return true;
    }

    public static int digit(long n) {
        int result = 0;
        while (n > 0) {
            n /= 10;
            result++;
        }
        return result;
    }

    public static double dist(long a, long b, long x, long y) {
        double val = (b - a) * (b - a) + (x - y) * (x - y);
        val = Math.sqrt(val);
        double other = x * x + a * a;
        other = Math.sqrt(other);
        return val + other;

    }

    public static class Point implements Comparable<Point> {

        int x, y;

        public Point(int start, int end) {
            this.x = start;
            this.y = end;
        }

        @Override
        public int hashCode() {
            int hash = 5;
            hash = 47 * hash + this.x;
            hash = 47 * hash + this.y;
            return hash;
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final Point other = (Point) obj;
            if (this.x != other.x) {
                return false;
            }
            if (this.y != other.y) {
                return false;
            }
            return true;
        }

        @Override
        public int compareTo(Point o) {
            return Integer.compare(x, o.x);
        }
    }

    public static class FT {

        long[] data;

        FT(int n) {
            data = new long[n];
        }

        public void update(int index, long value) {
            while (index < data.length) {
                data[index] += value;
                index += (index & (-index));
            }
        }

        public long get(int index) {
            long result = 0;
            while (index > 0) {
                result += data[index];
                index -= (index & (-index));
            }
            return result;

        }
    }

    public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    public static long pow(long a, long b, long MOD) {
        if (b == 0) {
            return 1;
        }
        if (b == 1) {
            return a;
        }
        long val = pow(a, b / 2, MOD);
        if (b % 2 == 0) {
            return val * val % MOD;
        } else {
            return val * (val * a % MOD) % MOD;

        }
    }

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() throws FileNotFoundException {
            // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
            //  br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt"))));
        }

        public String next() {

            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}

// package codeforces.cf3xx.cf356.div1;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

/**
 * Created by hama_du on 2016/12/15.
 */
public class C {

    private static int[] dx = new int[]{0, -1, 0, 1};
    private static int[] dy = new int[]{-1, 0, 1, 0};

    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = in.nextInt();
        int m = in.nextInt();
        int[][] field = new int[n][n];
        for (int i = 0; i < n ; i++) {
            char[] c = in.nextToken().toCharArray();
            for (int j = 0; j < n ; j++) {
                field[i][j] = c[j] == 'X' ? 1 : 0;
            }
        }

        int[][] imos = new int[n+1][n+1];
        for (int i = 0; i < n ; i++) {
            for (int j = 0; j < n ; j++) {
                imos[i+1][j+1] = imos[i+1][j] + imos[i][j+1] - imos[i][j] + field[i][j];
            }
        }

        UnionFind uf = new UnionFind(n*n);
        for (int i = 0; i < n ; i++) {
            for (int j = 0; j < n ; j++) {
                if (field[i][j] == 1) {
                    continue;
                }
                for (int d = 0; d < 4 ; d++) {
                    int ti = i+dy[d];
                    int tj = j+dx[d];
                    if (ti < 0 || tj < 0 || ti >= n || tj >= n || field[ti][tj] == 1) {
                        continue;
                    }
                    uf.unite(i*n+j, ti*n+tj);
                }
            }
        }

        id = new int[n][n];
        count = new int[n*n];
        for (int i = 0; i < n ; i++) {
            for (int j = 0; j < n ; j++) {
                if (field[i][j] == 1) {
                    id[i][j] = -1;
                    continue;
                }
                int x = uf.find(i*n+j);
                id[i][j] = x;
                count[x] = uf.groupCount(x);
            }
        }

        memo = new int[n*n];
        int max = 0;
        for (int i = 0 ; i+m <= n ; i++) {
            Arrays.fill(memo, 0);
            ans = 0;

            for (int j = 0; j < m ; j++) {
                for (int k = 0; k < m ; k++) {
                    push(i+j, k);
                }
            }

            for (int j = 0; j < m ; j++) {
                // up
                if (i-1 >= 0) {
                    push(i-1, j);
                }
                // dw
                if (i+m < n) {
                    push(i+m, j);
                }
                // rg
                if (m < n) {
                    push(i+j, m);
                }
            }

            for (int j = 0; j+m <= n ; j++) {
                int to = ans + imos[i+m][j+m] - imos[i][j+m] - imos[i+m][j] + imos[i][j];
                max = Math.max(max, to);

                // remove
                if (j >= 1) {
                    for (int k = 0; k < m ; k++) {
                        pop(i+k, j-1);
                    }
                }
                if (i-1 >= 0) {
                    pop(i-1, j);
                }
                if (i+m < n) {
                    pop(i+m, j);
                }

                // add
                if (j+m < n) {
                    if (i-1 >= 0) {
                        push(i-1, j+m);
                    }
                    if (i+m < n) {
                        push(i+m, j+m);
                    }
                }
                if (j+m+1 < n) {
                    for (int k = 0; k < m; k++) {
                        push(i+k, m+j+1);
                    }
                }
            }
        }

        out.println(max);
        out.flush();
    }

    static int ans;

    static int[][] id;
    static int[] count;
    static int[] memo;

    static void push(int i, int j) {
        int d = id[i][j];
        if (d == -1) {
            return;
        }
        if (memo[d] == 0) {
            ans += count[d];
        }
        memo[d]++;
    }

    static void pop(int i, int j) {
        int d = id[i][j];
        if (d == -1) {
            return;
        }
        if (memo[d] == 1) {
            ans -= count[d];
        }
        memo[d]--;
    }

    static class UnionFind {
        int[] rank;
        int[] parent;
        int[] cnt;

        public UnionFind(int n) {
            rank = new int[n];
            parent = new int[n];
            cnt = new int[n];
            for (int i = 0; i < n ; i++) {
                parent[i] = i;
                cnt[i] = 1;
            }
        }

        public int find(int a) {
            if (parent[a] == a) {
                return a;
            }
            parent[a] = find(parent[a]);
            return parent[a];
        }

        public void unite(int a, int b) {
            a = find(a);
            b = find(b);
            if (a == b) {
                return;
            }
            if (rank[a] < rank[b]) {
                parent[a] = b;
                cnt[b] += cnt[a];
                cnt[a] = cnt[b];
            } else {
                parent[b] = a;
                cnt[a] += cnt[b];
                cnt[b] = cnt[a];
                if (rank[a] == rank[b]) {
                    rank[a]++;
                }
            }
        }

        public int groupCount(int a) {
            return cnt[find(a)];
        }

        private boolean issame(int a, int b) {
            return find(a) == find(b);
        }
    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        private int[] nextInts(int n) {
            int[] ret = new int[n];
            for (int i = 0; i < n; i++) {
                ret[i] = nextInt();
            }
            return ret;
        }

        private int[][] nextIntTable(int n, int m) {
            int[][] ret = new int[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    ret[i][j] = nextInt();
                }
            }
            return ret;
        }

        private long[] nextLongs(int n) {
            long[] ret = new long[n];
            for (int i = 0; i < n; i++) {
                ret[i] = nextLong();
            }
            return ret;
        }

        private long[][] nextLongTable(int n, int m) {
            long[][] ret = new long[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    ret[i][j] = nextLong();
                }
            }
            return ret;
        }

        private double[] nextDoubles(int n) {
            double[] ret = new double[n];
            for (int i = 0; i < n; i++) {
                ret[i] = nextDouble();
            }
            return ret;
        }

        private int next() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public char nextChar() {
            int c = next();
            while (isSpaceChar(c))
                c = next();
            if ('a' <= c && c <= 'z') {
                return (char) c;
            }
            if ('A' <= c && c <= 'Z') {
                return (char) c;
            }
            throw new InputMismatchException();
        }

        public String nextToken() {
            int c = next();
            while (isSpaceChar(c))
                c = next();
            StringBuilder res = new StringBuilder();
            do {
                res.append((char) c);
                c = next();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public int nextInt() {
            int c = next();
            while (isSpaceChar(c))
                c = next();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = next();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = next();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = next();
            while (isSpaceChar(c))
                c = next();
            long sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = next();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = next();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            return Double.valueOf(nextToken());
        }

        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }

    static void debug(Object... o) {
        System.err.println(Arrays.deepToString(o));
    }
}

//package round356;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class C2 {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
		int n = ni();
		int K = ni();
		char[][] map = nm(n,n);
		DJSet ds = new DJSet(n*n);
		for(int i = 0;i < n;i++){
			for(int j = 0;j < n;j++){
				if(map[i][j] == '.'){
					if(j+1 < n && map[i][j+1] == '.'){
						ds.union(i*n+j, i*n+j+1);
					}
					if(i+1 < n && map[i+1][j] == '.'){
						ds.union(i*n+j, (i+1)*n+j);
					}
				}
			}
		}

		int p = 0;
		int[] clus = new int[n*n];
		Arrays.fill(clus, -1);
		for(int i = 0;i < n;i++){
			for(int j = 0;j < n;j++){
				if(map[i][j] == '.' && ds.upper[i*n+j] < 0){
					clus[i*n+j] = p++;
				}
			}
		}

		int max = 0;
		for(int i = 0;i+K-1 < n;i++){
			int[] f = new int[125002];
			int h = K*K;
			for(int j = -1;j <= K;j++){
				for(int k = -1;k <= K;k++){
					int r = i+j, c = 0+k;
					if((j == -1 || j == K) && (k == -1 || k == K))continue;
					if(r >= 0 && r < n && c >= 0 && c < n){
						if(map[r][c] == '.'){
							int cl = clus[ds.root(r*n+c)];
							if(++f[cl] == 1){
								h += -ds.upper[ds.root(r*n+c)];
							}
							if(j >= 0 && j < K && k >= 0 && k < K){
								h--;
							}
						}
					}
				}
			}

			for(int j = 0;j+K-1 < n;j++){
//				tr(i, j, h);
				max = Math.max(max, h);
				for(int k = -1;k <= K;k++){
					int r = i+k, c = j+K+1;
					if(k == -1 || k == K)c--;
					if(r >= 0 && r < n && c >= 0 && c < n){
						if(map[r][c] == '.'){
							int cl = clus[ds.root(r*n+c)];
							if(++f[cl] == 1){
								h += -ds.upper[ds.root(r*n+c)];
							}
						}
					}
				}
				for(int k = 0;k < K;k++){
					int r = i+k, c = j+K;
					if(r >= 0 && r < n && c >= 0 && c < n){
						if(map[r][c] == '.'){
							h--;
						}
					}
				}
				for(int k = -1;k <= K;k++){
					int r = i+k, c = j-1;
					if(k == -1 || k == K)c++;
					if(r >= 0 && r < n && c >= 0 && c < n){
						if(map[r][c] == '.'){
							int cl = clus[ds.root(r*n+c)];
							if(--f[cl] == 0){
								h -= -ds.upper[ds.root(r*n+c)];
							}
						}
					}
				}
				for(int k = 0;k < K;k++){
					int r = i+k, c = j;
					if(r >= 0 && r < n && c >= 0 && c < n){
						if(map[r][c] == '.'){
							h++;
						}
					}
				}
			}
		}
		out.println(max);
	}

	public static class DJSet {
		public int[] upper;

		public DJSet(int n) {
			upper = new int[n];
			Arrays.fill(upper, -1);
		}

		public int root(int x) {
			return upper[x] < 0 ? x : (upper[x] = root(upper[x]));
		}

		public boolean equiv(int x, int y) {
			return root(x) == root(y);
		}

		public boolean union(int x, int y) {
			x = root(x);
			y = root(y);
			if (x != y) {
				if (upper[y] < upper[x]) {
					int d = x;
					x = y;
					y = d;
				}
				upper[x] += upper[y];
				upper[y] = x;
			}
			return x == y;
		}

		public int count() {
			int ct = 0;
			for (int u : upper)
				if (u < 0)
					ct++;
			return ct;
		}
	}

	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception { new C2().run(); }

	private byte[] inbuf = new byte[1024];
	private int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}

//package round356;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class C3 {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
		int n = ni();
		int K = ni();
		char[][] map = nm(n,n);
		DJSet ds = new DJSet(n*n);
		for(int i = 0;i < n;i++){
			for(int j = 0;j < n;j++){
				if(map[i][j] == '.'){
					if(j+1 < n && map[i][j+1] == '.'){
						ds.union(i*n+j, i*n+j+1);
					}
					if(i+1 < n && map[i+1][j] == '.'){
						ds.union(i*n+j, (i+1)*n+j);
					}
				}
			}
		}

		int p = 0;
		int[] clus = new int[n*n];
		int[] szs = new int[125005];
		Arrays.fill(clus, -1);
		for(int i = 0;i < n;i++){
			for(int j = 0;j < n;j++){
				if(map[i][j] == '.' && ds.upper[i*n+j] < 0){
					clus[i*n+j] = p;
					szs[p] = -ds.upper[i*n+j];
					p++;
				}
			}
		}
		int[][] cls = new int[n][n];
		for(int i = 0;i < n;i++){
			for(int j = 0;j < n;j++){
				cls[i][j] = clus[ds.root(i*n+j)];
			}
		}

		int max = 0;
		int[] f = new int[125002];
		int[] temp = new int[(K+2)*n];
		for(int i = 0;i+K-1 < n;i++){
			int tp = 0;
			int h = K*K;
			for(int j = -1;j <= K;j++){
				for(int k = -1;k <= K;k++){
					int r = i+j, c = 0+k;
					if((j == -1 || j == K) && (k == -1 || k == K))continue;
					if(r >= 0 && r < n && c >= 0 && c < n){
						if(map[r][c] == '.'){
							int cl = cls[r][c];
							temp[tp++] = cl;
							if(++f[cl] == 1){
								h += szs[cl];
							}
							if(j >= 0 && j < K && k >= 0 && k < K){
								h--;
							}
						}
					}
				}
			}

			for(int j = 0;j+K-1 < n;j++){
//				tr(i, j, h);
				max = Math.max(max, h);
				for(int k = -1;k <= K;k++){
					int r = i+k, c = j+K+1;
					if(k == -1 || k == K)c--;
					if(r >= 0 && r < n && c >= 0 && c < n){
						if(map[r][c] == '.'){
							int cl = cls[r][c];
							temp[tp++] = cl;
							if(++f[cl] == 1){
								h += szs[cl];
							}
						}
					}
				}
				for(int k = 0;k < K;k++){
					int r = i+k, c = j+K;
					if(r >= 0 && r < n && c >= 0 && c < n){
						if(map[r][c] == '.'){
							h--;
						}
					}
				}
				for(int k = -1;k <= K;k++){
					int r = i+k, c = j-1;
					if(k == -1 || k == K)c++;
					if(r >= 0 && r < n && c >= 0 && c < n){
						if(map[r][c] == '.'){
							int cl = cls[r][c];
							if(--f[cl] == 0){
								h -= szs[cl];
							}
						}
					}
				}
				for(int k = 0;k < K;k++){
					int r = i+k, c = j;
					if(r >= 0 && r < n && c >= 0 && c < n){
						if(map[r][c] == '.'){
							h++;
						}
					}
				}
			}
			for(int j = 0;j < tp;j++){
				f[temp[j]] = 0;
			}
		}
		out.println(max);
	}

	public static class DJSet {
		public int[] upper;

		public DJSet(int n) {
			upper = new int[n];
			Arrays.fill(upper, -1);
		}

		public int root(int x) {
			return upper[x] < 0 ? x : (upper[x] = root(upper[x]));
		}

		public boolean equiv(int x, int y) {
			return root(x) == root(y);
		}

		public boolean union(int x, int y) {
			x = root(x);
			y = root(y);
			if (x != y) {
				if (upper[y] < upper[x]) {
					int d = x;
					x = y;
					y = d;
				}
				upper[x] += upper[y];
				upper[y] = x;
			}
			return x == y;
		}

		public int count() {
			int ct = 0;
			for (int u : upper)
				if (u < 0)
					ct++;
			return ct;
		}
	}

	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception { new C3().run(); }

	private byte[] inbuf = new byte[1024];
	private int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}

//package round356;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class C3 {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
		int n = ni();
		int K = ni();
		char[][] map = nm(n,n);
		DJSet ds = new DJSet(n*n);
		for(int i = 0;i < n;i++){
			for(int j = 0;j < n;j++){
				if(map[i][j] == '.'){
					if(j+1 < n && map[i][j+1] == '.'){
						ds.union(i*n+j, i*n+j+1);
					}
					if(i+1 < n && map[i+1][j] == '.'){
						ds.union(i*n+j, (i+1)*n+j);
					}
				}
			}
		}

		int p = 0;
		int[] clus = new int[n*n];
		int[] szs = new int[125005];
		Arrays.fill(clus, -1);
		for(int i = 0;i < n;i++){
			for(int j = 0;j < n;j++){
				if(map[i][j] == '.' && ds.upper[i*n+j] < 0){
					clus[i*n+j] = p;
					szs[p] = -ds.upper[i*n+j];
					p++;
				}
			}
		}
		int[][] cls = new int[n][n];
		for(int i = 0;i < n;i++){
			for(int j = 0;j < n;j++){
				cls[i][j] = clus[ds.root(i*n+j)];
			}
		}

		int max = 0;
		int[] f = new int[125002];
		for(int i = 0;i+K-1 < n;i++){
			int h = K*K;
			for(int j = -1;j <= K;j++){
				for(int k = -1;k <= K;k++){
					int r = i+j, c = 0+k;
					if((j == -1 || j == K) && (k == -1 || k == K))continue;
					if(r >= 0 && r < n && c >= 0 && c < n){
						if(map[r][c] == '.'){
							int cl = cls[r][c];
							if(++f[cl] == 1){
								h += szs[cl];
							}
							if(j >= 0 && j < K && k >= 0 && k < K){
								h--;
							}
						}
					}
				}
			}

			for(int j = 0;j+K-1 < n;j++){
//				tr(i, j, h);
				max = Math.max(max, h);
				for(int k = -1;k <= K;k++){
					int r = i+k, c = j+K+1;
					if(k == -1 || k == K)c--;
					if(r >= 0 && r < n && c >= 0 && c < n){
						if(map[r][c] == '.'){
							int cl = cls[r][c];
							if(++f[cl] == 1){
								h += szs[cl];
							}
						}
					}
				}
				for(int k = 0;k < K;k++){
					int r = i+k, c = j+K;
					if(r >= 0 && r < n && c >= 0 && c < n){
						if(map[r][c] == '.'){
							h--;
						}
					}
				}
				for(int k = -1;k <= K;k++){
					int r = i+k, c = j-1;
					if(k == -1 || k == K)c++;
					if(r >= 0 && r < n && c >= 0 && c < n){
						if(map[r][c] == '.'){
							int cl = cls[r][c];
							if(--f[cl] == 0){
								h -= szs[cl];
							}
						}
					}
				}
				for(int k = 0;k < K;k++){
					int r = i+k, c = j;
					if(r >= 0 && r < n && c >= 0 && c < n){
						if(map[r][c] == '.'){
							h++;
						}
					}
				}
			}
			for(int j = -1;j <= K;j++){
				for(int k = 0;k < n;k++){
					int r = i+j, c = 0+k;
					if(r >= 0 && r < n && c >= 0 && c < n){
						if(map[r][c] == '.'){
							int cl = cls[r][c];
							f[cl] = 0;
						}
					}
				}
			}
		}
		out.println(max);
	}

	public static class DJSet {
		public int[] upper;

		public DJSet(int n) {
			upper = new int[n];
			Arrays.fill(upper, -1);
		}

		public int root(int x) {
			return upper[x] < 0 ? x : (upper[x] = root(upper[x]));
		}

		public boolean equiv(int x, int y) {
			return root(x) == root(y);
		}

		public boolean union(int x, int y) {
			x = root(x);
			y = root(y);
			if (x != y) {
				if (upper[y] < upper[x]) {
					int d = x;
					x = y;
					y = d;
				}
				upper[x] += upper[y];
				upper[y] = x;
			}
			return x == y;
		}

		public int count() {
			int ct = 0;
			for (int u : upper)
				if (u < 0)
					ct++;
			return ct;
		}
	}

	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception { new C3().run(); }

	private byte[] inbuf = new byte[1024];
	private int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}

//package round356;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class C3 {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
		int n = ni();
		int K = ni();
		char[][] map = nm(n,n);
		DJSet ds = new DJSet(n*n);
		for(int i = 0;i < n;i++){
			for(int j = 0;j < n;j++){
				if(map[i][j] == '.'){
					if(j+1 < n && map[i][j+1] == '.'){
						ds.union(i*n+j, i*n+j+1);
					}
					if(i+1 < n && map[i+1][j] == '.'){
						ds.union(i*n+j, (i+1)*n+j);
					}
				}
			}
		}

		int p = 0;
		int[] clus = new int[n*n];
		int[] szs = new int[125005];
		Arrays.fill(clus, -1);
		for(int i = 0;i < n;i++){
			for(int j = 0;j < n;j++){
				if(map[i][j] == '.' && ds.upper[i*n+j] < 0){
					clus[i*n+j] = p;
					szs[p] = -ds.upper[i*n+j];
					p++;
				}
			}
		}
		int[][] cls = new int[n][n];
		for(int i = 0;i < n;i++){
			for(int j = 0;j < n;j++){
				cls[i][j] = clus[ds.root(i*n+j)];
			}
		}

		int max = 0;
		int[] f = new int[125002];
		for(int i = 0;i+K-1 < n;i++){
			Arrays.fill(f, 0);
			int h = K*K;
			for(int j = -1;j <= K;j++){
				for(int k = -1;k <= K;k++){
					int r = i+j, c = 0+k;
					if((j == -1 || j == K) && (k == -1 || k == K))continue;
					if(r >= 0 && r < n && c >= 0 && c < n){
						if(map[r][c] == '.'){
							int cl = cls[r][c];
							if(++f[cl] == 1){
								h += szs[cl];
							}
							if(j >= 0 && j < K && k >= 0 && k < K){
								h--;
							}
						}
					}
				}
			}

			for(int j = 0;j+K-1 < n;j++){
//				tr(i, j, h);
				max = Math.max(max, h);
				for(int k = -1;k <= K;k++){
					int r = i+k, c = j+K+1;
					if(k == -1 || k == K)c--;
					if(r >= 0 && r < n && c >= 0 && c < n){
						if(map[r][c] == '.'){
							int cl = cls[r][c];
							if(++f[cl] == 1){
								h += szs[cl];
							}
						}
					}
				}
				for(int k = 0;k < K;k++){
					int r = i+k, c = j+K;
					if(r >= 0 && r < n && c >= 0 && c < n){
						if(map[r][c] == '.'){
							h--;
						}
					}
				}
				for(int k = -1;k <= K;k++){
					int r = i+k, c = j-1;
					if(k == -1 || k == K)c++;
					if(r >= 0 && r < n && c >= 0 && c < n){
						if(map[r][c] == '.'){
							int cl = cls[r][c];
							if(--f[cl] == 0){
								h -= szs[cl];
							}
						}
					}
				}
				for(int k = 0;k < K;k++){
					int r = i+k, c = j;
					if(r >= 0 && r < n && c >= 0 && c < n){
						if(map[r][c] == '.'){
							h++;
						}
					}
				}
			}
		}
		out.println(max);
	}

	public static class DJSet {
		public int[] upper;

		public DJSet(int n) {
			upper = new int[n];
			Arrays.fill(upper, -1);
		}

		public int root(int x) {
			return upper[x] < 0 ? x : (upper[x] = root(upper[x]));
		}

		public boolean equiv(int x, int y) {
			return root(x) == root(y);
		}

		public boolean union(int x, int y) {
			x = root(x);
			y = root(y);
			if (x != y) {
				if (upper[y] < upper[x]) {
					int d = x;
					x = y;
					y = d;
				}
				upper[x] += upper[y];
				upper[y] = x;
			}
			return x == y;
		}

		public int count() {
			int ct = 0;
			for (int u : upper)
				if (u < 0)
					ct++;
			return ct;
		}
	}

	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception { new C3().run(); }

	private byte[] inbuf = new byte[1024];
	private int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}

//package round356;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class C3 {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
		int n = ni();
		int K = ni();
		char[][] map = nm(n,n);
		DJSet ds = new DJSet(n*n);
		for(int i = 0;i < n;i++){
			for(int j = 0;j < n;j++){
				if(map[i][j] == '.'){
					if(j+1 < n && map[i][j+1] == '.'){
						ds.union(i*n+j, i*n+j+1);
					}
					if(i+1 < n && map[i+1][j] == '.'){
						ds.union(i*n+j, (i+1)*n+j);
					}
				}
			}
		}

		int p = 0;
		int[] clus = new int[n*n];
		int[] szs = new int[125005];
		Arrays.fill(clus, -1);
		for(int i = 0;i < n;i++){
			for(int j = 0;j < n;j++){
				if(map[i][j] == '.' && ds.upper[i*n+j] < 0){
					clus[i*n+j] = p;
					szs[p] = -ds.upper[i*n+j];
					p++;
				}
			}
		}
		int[][] cls = new int[n][n];
		for(int i = 0;i < n;i++){
			for(int j = 0;j < n;j++){
				cls[i][j] = clus[ds.root(i*n+j)];
			}
		}

		int max = 0;
		for(int i = 0;i+K-1 < n;i++){
			int[] f = new int[125002];
			int h = K*K;
			for(int j = -1;j <= K;j++){
				for(int k = -1;k <= K;k++){
					int r = i+j, c = 0+k;
					if((j == -1 || j == K) && (k == -1 || k == K))continue;
					if(r >= 0 && r < n && c >= 0 && c < n){
						if(map[r][c] == '.'){
							int cl = cls[r][c];
							if(++f[cl] == 1){
								h += szs[cl];
							}
							if(j >= 0 && j < K && k >= 0 && k < K){
								h--;
							}
						}
					}
				}
			}

			for(int j = 0;j+K-1 < n;j++){
//				tr(i, j, h);
				max = Math.max(max, h);
				for(int k = -1;k <= K;k++){
					int r = i+k, c = j+K+1;
					if(k == -1 || k == K)c--;
					if(r >= 0 && r < n && c >= 0 && c < n){
						if(map[r][c] == '.'){
							int cl = cls[r][c];
							if(++f[cl] == 1){
								h += szs[cl];
							}
						}
					}
				}
				for(int k = 0;k < K;k++){
					int r = i+k, c = j+K;
					if(r >= 0 && r < n && c >= 0 && c < n){
						if(map[r][c] == '.'){
							h--;
						}
					}
				}
				for(int k = -1;k <= K;k++){
					int r = i+k, c = j-1;
					if(k == -1 || k == K)c++;
					if(r >= 0 && r < n && c >= 0 && c < n){
						if(map[r][c] == '.'){
							int cl = cls[r][c];
							if(--f[cl] == 0){
								h -= szs[cl];
							}
						}
					}
				}
				for(int k = 0;k < K;k++){
					int r = i+k, c = j;
					if(r >= 0 && r < n && c >= 0 && c < n){
						if(map[r][c] == '.'){
							h++;
						}
					}
				}
			}
		}
		out.println(max);
	}

	public static class DJSet {
		public int[] upper;

		public DJSet(int n) {
			upper = new int[n];
			Arrays.fill(upper, -1);
		}

		public int root(int x) {
			return upper[x] < 0 ? x : (upper[x] = root(upper[x]));
		}

		public boolean equiv(int x, int y) {
			return root(x) == root(y);
		}

		public boolean union(int x, int y) {
			x = root(x);
			y = root(y);
			if (x != y) {
				if (upper[y] < upper[x]) {
					int d = x;
					x = y;
					y = d;
				}
				upper[x] += upper[y];
				upper[y] = x;
			}
			return x == y;
		}

		public int count() {
			int ct = 0;
			for (int u : upper)
				if (u < 0)
					ct++;
			return ct;
		}
	}

	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception { new C3().run(); }

	private byte[] inbuf = new byte[1024];
	private int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}

import java.io.*;
import java.util.*;

public class C {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	int n;
	int k;

	char[][] f;

	int[][] color;
	List<Integer> sizeAL;

	int[] size;

	static final int[] DX = { -1, 0, 1, 0 };
	static final int[] DY = { 0, -1, 0, 1 };

	int dfs(int x, int y, int cur) {
		color[x][y] = cur;
		int ret = 1;
		for (int d = 0; d < 4; d++) {
			int cx = x + DX[d];
			int cy = y + DY[d];
			if (cx >= 0 && cx < n && cy >= 0 && cy < n && f[cx][cy] == '.'
					&& color[cx][cy] == 0) {
				ret += dfs(cx, cy, cur);
			}
		}
		return ret;
	}

	static class Counter {
		int[] count;
		int[] score;

		int sum = 0;

		void modify(int idx, int delta) {
			if (count[idx] != 0) {
				sum -= score[idx];
			}
			count[idx] += delta;
			if (count[idx] != 0) {
				sum += score[idx];
			}
		}

		int getSum() {
			return sum;
		}

		void clear() {
			Arrays.fill(count, 0);
			sum = 0;
		}

		public Counter(int[] score) {
			this.score = score;
			count = new int[score.length];
		}

	}

	void solve() throws IOException {
		n = nextInt();
		k = nextInt();

		f = new char[n][];
		for (int i = 0; i < n; i++) {
			f[i] = nextToken().toCharArray();
		}

		color = new int[n][n];
		sizeAL = new ArrayList<>();

		int comps = 0;

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (f[i][j] == '.' && color[i][j] == 0) {
					comps++;
					sizeAL.add(dfs(i, j, comps));
				}
			}
		}

		size = new int[comps];
		for (int i = 0; i < comps; i++) {
			size[i] = sizeAL.get(i);
		}

//		System.err.println(Arrays.deepToString(color));
//		System.err.println(Arrays.toString(size));

		Counter counter = new Counter(size);

		int ans = -1;

		for (int top = 0; top <= n - k; top++) {

			counter.clear();
			int xs = 0;

			for (int x = top - 1; x < top + k + 1; x++)
				for (int y = 0; y < k + 1 && y < n; y++) {

					if (x < 0 || x >= n) {
						continue;
					}

					int status = ((x == top - 1 || x == top + k) ? 1 : 0)
							+ (y == k ? 1 : 0);

					if (status == 2) {
						continue;
					}

					if (color[x][y] != 0) {
						counter.modify(color[x][y] - 1, 1);
					} else {
						if (status == 0) {
							xs++;
						}
					}
				}

			int value = counter.getSum() + xs;
//			System.err.println(value - xs);
//			System.err.println(xs);
//			System.err.println("--------");
			ans = Math.max(ans, value);

			for (int left = 1; left <= n - k; left++) {

				// update counter
				for (int x = top - 1; x <= top + k; x++) {
					if (x < 0 || x >= n) {
						continue;
					}
					int y1 = (x == top - 1 || x == top + k) ? left  - 1: left - 2;
					if (y1 >= 0 && y1 < n && color[x][y1] != 0) {
						counter.modify(color[x][y1] - 1, -1);
					}

					int y2 = (x == top - 1 || x == top + k) ? left + k - 1
							: left + k;
					if (y2 >= 0 && y2 < n && color[x][y2] != 0) {
						counter.modify(color[x][y2] - 1, 1);
					}
				}

				// update xs
				for (int x = top; x < top + k; x++) {
					if (color[x][left - 1] == 0) {
						xs--;
					}
					if (left + k - 1 < n && color[x][left + k - 1] == 0) {
						xs++;
					}
				}

				value = counter.getSum() + xs;
//				System.err.println(value);
				ans = Math.max(ans, value);

			}

		}

		out.println(ans);
	}

	C() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new C();
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return null;
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}

import java.io.*;
import java.util.*;

public class C356C
{
    public static StringTokenizer st;
    public static void nextLine(BufferedReader br) throws IOException
    {
        st = new StringTokenizer(br.readLine());
    }

    public static String next()
    {
        return st.nextToken();
    }

    public static int nextInt()
    {
        return Integer.parseInt(st.nextToken());
    }

    public static long nextLong()
    {
        return Long.parseLong(st.nextToken());
    }

    public static double nextDouble()
    {
        return Double.parseDouble(st.nextToken());
    }

    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        nextLine(br);
        int n = nextInt();
        int k = nextInt();
        int[][] board = new int[n][n];
        for (int i = 0; i < n; i++)
        {
            nextLine(br);
            String s = next();
            for (int j = 0; j < n; j++)
            {
                board[i][j] = (s.charAt(j) == '.') ? 0 : 1;
            }
        }
        int[][] bsum = new int[n+1][n+1];
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= n; j++)
            {
                bsum[i][j] = bsum[i-1][j] + bsum[i][j-1] - bsum[i-1][j-1] + board[i-1][j-1];
            }
        }
        int[][] group = new int[n][n];
        int ctr = 1;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                if (group[i][j] > 0 || board[i][j] == 1) continue;
                ffill(group, board, i, j, ctr);
                ctr++;
            }
        }
        int[] freqs = new int[ctr];
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                if (group[i][j] > 0)
                {
                    freqs[group[i][j]]++;
                }
            }
        }
        int max = 0;
        for (int i = 0; i + k <= n; i++)
        {
            int[] count = new int[ctr];
            int sum = 0;
            for (int r = i; r < i + k; r++)
            {
                for (int c = 0; c < k; c++)
                {
                    if (group[r][c] > 0)
                    {
                        if (count[group[r][c]] == 0)
                        {
                            sum += freqs[group[r][c]];
                        }
                        count[group[r][c]]++;
                    }
                }
            }
            if (i > 0) // top
            {
                for (int c = 0; c < k; c++)
                {
                    if (group[i-1][c] > 0)
                    {
                        if (count[group[i-1][c]] == 0)
                        {
                            sum += freqs[group[i-1][c]];
                        }
                        count[group[i-1][c]]++;
                    }
                }
            }
            if (i + k < n) // bottom
            {
                for (int c = 0; c < k; c++)
                {
                    if (group[i+k][c] > 0)
                    {
                        int idx = group[i+k][c];
                        if (count[idx] == 0)
                        {
                            sum += freqs[idx];
                        }
                        count[idx]++;
                    }
                }
            }
            if (k < n)
            {
                for (int r = i; r < i + k; r++)
                {
                    if (group[r][k] > 0)
                    {
                        if (count[group[r][k]] == 0)
                        {
                            sum += freqs[group[r][k]];
                        }
                        count[group[r][k]]++;
                    }
                }
            }
            int total = sum + (bsum[i+k][k] - bsum[i][k] - bsum[i+k][0] + bsum[i][0]);
            //System.out.println("At " + i + ",0 " + total + " " + Arrays.toString(count));
            max = Math.max(max, total);
            for (int j = 1; j + k <= n; j++)
            {
                if (j > 1)
                {
                    for (int r = i; r < i + k; r++)
                    {
                        if (group[r][j-2] > 0)
                        {
                            //System.out.println("Killing " + r + " " + (j-2));
                            count[group[r][j-2]]--;
                            if (count[group[r][j-2]] == 0)
                            {
                                sum -= freqs[group[r][j-2]];
                            }
                        }
                    }
                }
                if (j+k < n)
                {
                    for (int r = i; r < i + k; r++)
                    {
                        if (group[r][j+k] > 0)
                        {
                            //System.out.println("*Adding " + r + " " + (j+k));
                            if (count[group[r][j+k]] == 0)
                            {
                                sum += freqs[group[r][j+k]];
                            }
                            count[group[r][j+k]]++;
                        }
                    }
                }
                if (i > 0)
                {
                    if (group[i-1][j+k-1] > 0)
                    {
                        //System.out.println("Adding " + (i-1) + " " + (j+k-1));
                        int idx = group[i-1][j+k-1];
                        if (count[idx] == 0)
                        {
                            sum += freqs[idx];
                        }
                        count[idx]++;
                    }
                    if (group[i-1][j-1] > 0)
                    {
                        //System.out.println("Killing " + (i-1) + " " + (j-1));
                        int idx = group[i-1][j-1];
                        count[idx]--;
                        if (count[idx] == 0)
                        {
                            sum -= freqs[idx];
                        }
                    }
                }
                if (i + k < n)
                {
                    if (group[i+k][j+k-1] > 0)
                    {
                        //System.out.println("Adding " + (i+k) + " " + (j+k-1));
                        int idx = group[i+k][j+k-1];
                        if (count[idx] == 0)
                        {
                            sum += freqs[idx];
                        }
                        count[idx]++;
                    }
                    if (group[i+k][j-1] > 0)
                    {
                        //System.out.println("Killing " + (i+k) + " " + (j-1));
                        int idx = group[i+k][j-1];
                        count[idx]--;
                        if (count[idx] == 0)
                        {
                            sum -= freqs[idx];
                        }
                    }
                }
                total = sum + (bsum[i+k][j+k] - bsum[i][j+k] - bsum[i+k][j] + bsum[i][j]);
                //System.out.println("At " + i + "," + j + " " + total + " " + Arrays.toString(count));
                max = Math.max(max, total);
            }
        }
        System.out.println(max);
    }

    static void ffill(int[][] group, int[][] board, int r, int c, int index)
    {
        group[r][c] = index;
        if (r > 0 && board[r-1][c] == 0 && group[r-1][c] == 0)
        {
            ffill(group, board, r-1, c, index);
        }
        if (r < board.length -1 && board[r+1][c] == 0 && group[r+1][c] == 0)
        {
            ffill(group, board, r+1, c, index);
        }
        if (c > 0 && board[r][c-1] == 0 && group[r][c-1] == 0)
        {
            ffill(group, board, r, c-1, index);
        }
        if (c < board[0].length -1 && board[r][c+1] == 0 && group[r][c+1] == 0)
        {
            ffill(group, board, r, c+1, index);
        }
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Set;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.FileNotFoundException;
import java.io.File;
import java.util.HashSet;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.UnsupportedEncodingException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author shu_mj @ http://shu-mj.com
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        Printer out = new Printer(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        Scanner in;
        Printer out;
        int[] dx = {0, 0, 1, -1};
        int[] dy = {1, -1, 0, 0};

        public void solve(int testNumber, Scanner in, Printer out) {
            this.in = in;
            this.out = out;
            run();
        }

        void run() {
            int n = in.nextInt();
            int k = in.nextInt();
            char[][] maps = in.nextCharMatrix(n);
            int[][] id = new int[n][n];
            Sequence.fill(id, -1);
            int ic = 0;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if (maps[i][j] == '.' && id[i][j] == -1) {
                        dfs(maps, id, i, j, ic++);
                    }
                }
            }
            int[] cnt = new int[ic];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if (id[i][j] != -1) {
                        cnt[id[i][j]]++;
                    }
                }
            }
            int res = 0;
            int p = 0;
            int[] ps = new int[ic];
            for (int i = 0; i + k <= n; i++) {
                int[] inc = new int[ic];
                int ri = 0;
                for (int u = 0; u < k; u++) {
                    for (int v = 0; v < k; v++) {
                        int ie = id[i + u][v];
                        if (ie != -1) {
                            if (inc[ie] == 0) ri += cnt[ie];
                            inc[ie]++;
                            ri--;
                        }
                    }
                }
                {
                    Set<Integer> vis = new HashSet<>();
                    int tmp = 0;
                    p++;
                    tmp += go(id, cnt, inc, ps, p, k, i, k, 1, 0);
                    tmp += go(id, cnt, inc, ps, p, k, i - 1, 0, 0, 1);
                    tmp += go(id, cnt, inc, ps, p, k, i + k, 0, 0, 1);
                    res = Math.max(res, ri + tmp);
                }
                for (int j = 0; j + k < n; j++) {
                    for (int u = 0; u < k; u++) {
                        int ie = id[i + u][j];
                        if (ie != -1) {
                            inc[ie]--;
                            ri++;
                            if (inc[ie] == 0) ri -= cnt[ie];
                        }
                    }
                    for (int u = 0; u < k; u++) {
                        int ie = id[i + u][j + k];
                        if (ie != -1) {
                            if (inc[ie] == 0) ri += cnt[ie];
                            inc[ie]++;
                            ri--;
                        }
                    }
                    Set<Integer> vis = new HashSet<>();
                    int tmp = 0;
                    p++;
                    tmp += go(id, cnt, inc, ps, p, k, i, j, 1, 0);
                    tmp += go(id, cnt, inc, ps, p, k, i, j + k + 1, 1, 0);
                    tmp += go(id, cnt, inc, ps, p, k, i - 1, j + 1, 0, 1);
                    tmp += go(id, cnt, inc, ps, p, k, i + k, j + 1, 0, 1);
                    res = Math.max(res, ri + tmp);
                }
            }
            out.println(res + k * k);
        }

        private int go(int[][] id, int[] cnt, int[] inc, int[] ps, int p, int k, int i, int j, int di, int dj) {
            int res = 0;
            if (i >= 0 && j >= 0 && i + di * (k - 1) < id.length && j + dj * (k - 1) < id.length) {
                for (int u = 0; u < k; u++) {
                    int x = i + di * u;
                    int y = j + dj * u;
                    int ie = id[x][y];
                    if (ie != -1 && inc[ie] == 0 && ps[ie] != p) {
                        ps[ie] = p;
                        res += cnt[ie];
                    }
                }
            }
            return res;
        }

        private void dfs(char[][] maps, int[][] id, int r, int c, int ic) {
            id[r][c] = ic;
            for (int i = 0; i < 4; i++) {
                int x = r + dx[i];
                int y = c + dy[i];
                if (x >= 0 && y >= 0 && x < maps.length && y < maps[0].length) {
                    if (maps[x][y] == '.' && id[x][y] == -1) {
                        dfs(maps, id, x, y, ic);
                    }
                }
            }
        }

    }

    static class Scanner {
        BufferedReader br;
        StringTokenizer st;

        public Scanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
            eat("");
        }

        private void eat(String s) {
            st = new StringTokenizer(s);
        }

        public String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                return null;
            }
        }

        public boolean hasNext() {
            while (!st.hasMoreTokens()) {
                String s = nextLine();
                if (s == null)
                    return false;
                eat(s);
            }
            return true;
        }

        public String next() {
            hasNext();
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public char[] nextCharArray() {
            return next().toCharArray();
        }

        public char[][] nextCharMatrix(int row) {
            char[][] mat = new char[row][];
            for (int i = 0; i < row; i++) {
                mat[i] = nextCharArray();
            }
            return mat;
        }

    }

    static class Sequence {
        public static void fill(int[][] a, int v) {
            for (int[] b : a) {
                fill(b, v);
            }
        }

        public static void fill(int[] a, int v) {
            Arrays.fill(a, v);
        }

    }

    static class Printer extends PrintWriter {
        public Printer(Writer out) {
            super(out);
        }

        public Printer(Writer out, boolean autoFlush) {
            super(out, autoFlush);
        }

        public Printer(OutputStream out) {
            super(out);
        }

        public Printer(OutputStream out, boolean autoFlush) {
            super(out, autoFlush);
        }

        public Printer(String fileName) throws FileNotFoundException {
            super(fileName);
        }

        public Printer(String fileName, String csn) throws FileNotFoundException, UnsupportedEncodingException {
            super(fileName, csn);
        }

        public Printer(File file) throws FileNotFoundException {
            super(file);
        }

        public Printer(File file, String csn) throws FileNotFoundException, UnsupportedEncodingException {
            super(file, csn);
        }

    }
}

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Set;

public class Round356_E_postContest_v2 {

    static final int WALL = 0;
    static final int EMPTY_NOT_DISCOVERED = -1;

    public static void main(String[] args) throws IOException {
        FastReader in = new FastReader(System.in);
        PrintWriter out = new PrintWriter(System.out);

        // read input

        int n = in.readInt();
        int k = in.readInt();

        int[][] grid = new int[n][n];
        for (int i = 0 ; i < n ; i++) {
            for (int j = 0 ; j < n ; j++) {
                char c = in.readChar();
                grid[i][j] = (c == '.') ? EMPTY_NOT_DISCOVERED : WALL;
            }
        }

        // find components
        int components = 0;
        for (int i = 0 ; i < n ; i++) {
            for (int j = 0 ; j < n ; j++) {
                if (grid[i][j] == EMPTY_NOT_DISCOVERED) {
                    discover(grid, i, j, ++components);
                }
            }
        }
        // each grid[i][j] cell now holds either 0 (WALL) or number of the component (1..x)

        // compute component sizes
        int[] componentSize = new int[components + 1];
        for (int i = 0 ; i < n ; i++) {
            for (int j = 0 ; j < n ; j++) {
                if (grid[i][j] != WALL) {
                    componentSize[grid[i][j]]++;
                }
            }
        }

        // initialize window
        int insideTotal = 0;
        int[] outside = Arrays.copyOf(componentSize, componentSize.length);
        for (int i = 0 ; i < k ; i++) {
            for (int j = 0 ; j < k ; j++) {
                if (grid[i][j] != WALL) {
                    insideTotal++;
                    outside[grid[i][j]]--;
                }
            }
        }

        // ...and move the window across board
        int xTop = 0;
        int yTop = 0;
        int dx = +1;
        int solution = 0;
        int[] flags = new int[components + 1];
        int flag = 0;
        while (true) {

            flag++;
            int cur = k*k;
            for (int off = 0 ; off < k ; off++) {
                if (xTop - 1 >= 0) {
                    int comp = grid[xTop - 1][yTop + off];
                    if (comp != WALL && flags[comp] != flag) {
                        cur += outside[comp];
                        flags[comp] = flag;
                    }
                }
                if (xTop + k < n) {
                    int comp = grid[xTop + k][yTop + off];
                    if (comp != WALL && flags[comp] != flag) {
                        cur += outside[comp];
                        flags[comp] = flag;
                    }
                }
                if (yTop - 1 >= 0) {
                    int comp = grid[xTop + off][yTop - 1];
                    if (comp != WALL && flags[comp] != flag) {
                        cur += outside[comp];
                        flags[comp] = flag;
                    }
                }
                if (yTop + k < n) {
                    int comp = grid[xTop + off][yTop + k];
                    if (comp != WALL && flags[comp] != flag) {
                        cur += outside[comp];
                        flags[comp] = flag;
                    }
                }
            }
            solution = Math.max(solution, cur);

            boolean moveRight = dx == +1 && (xTop + k + 1 <= n);
            boolean moveLeft  = dx == -1 && (xTop - 1 >= 0);
            boolean moveDown  = !moveRight && !moveLeft;
            if (moveRight) {
                for (int off = 0; off < k; off++) {
                    if (grid[xTop][yTop + off] != WALL) {
                        outside[grid[xTop][yTop + off]]++;
                    }
                    if (grid[xTop + k][yTop + off] != WALL) {
                        outside[grid[xTop + k][yTop + off]]--;
                    }
                }
                xTop++;
            } else if (moveLeft) {
                for (int off = 0 ; off < k ; off++) {
                    if (grid[xTop + k - 1][yTop + off] != WALL) {
                        outside[grid[xTop + k - 1][yTop + off]]++;
                    }
                    if (grid[xTop - 1][yTop + off] != WALL) {
                        outside[grid[xTop - 1][yTop + off]]--;
                    }
                }
                xTop--;
            } else {
                if (yTop + k == n) {
                    break;
                }

                for (int off = 0 ; off < k ; off++) {
                    if (grid[xTop + off][yTop] != WALL) {
                        outside[grid[xTop + off][yTop]]++;
                    }
                    if (grid[xTop + off][yTop + k] != WALL) {
                        outside[grid[xTop + off][yTop + k]]--;
                    }
                }
                dx *= -1;
                yTop++;
            }
        }

        out.println(solution);
        out.flush();
    }

    private static void discover(int[][] grid, int i, int j, int componentNo) {
        int n = grid.length;
        LinkedList<int[]> open = new LinkedList<>();

        grid[i][j] = componentNo;
        open.add(new int[] {i,j});

        while (!open.isEmpty()) {
            int[] xy = open.removeFirst();
            int x = xy[0];
            int y = xy[1];

            for (int[] xxyy : new int[][] {{x-1, y}, {x+1,y}, {x,y+1}, {x,y-1}}) {
                int xx = xxyy[0];
                int yy = xxyy[1];
                if (0 <= xx && xx < n && 0 <= yy && yy < n) {
                    if (grid[xx][yy] == EMPTY_NOT_DISCOVERED) {
                        grid[xx][yy] = componentNo;
                        open.add(new int[] {xx, yy});
                    }
                }
            }
        }
    }

    private static void add(int[] cntPerComponent, Set<Integer> nonZeroCntComponents, int[][] grid, int i, int j) {
        if (isValid(grid, i, j) && grid[i][j] != WALL) {
            if (cntPerComponent[grid[i][j]]++ == 0) {
                nonZeroCntComponents.add(grid[i][j]);
            }
        }
    }

    private static void remove(int[] cntPerComponent, Set<Integer> nonZeroCntComponents, int[][] grid, int i, int j) {
        if (isValid(grid, i, j) && grid[i][j] != WALL) {
            if (--cntPerComponent[grid[i][j]] == 0) {
                nonZeroCntComponents.remove(grid[i][j]);
            }
        }
    }

    private static boolean isValid(int[][] grid, int i, int j) {
        int n = grid.length;
        return (0 <= i && i < n && 0 <= j && j < n);
    }

    /**
     * Custom buffered reader. Faster than Scanner and
     * BufferedReader + StringTokenizer.
     */
    static class FastReader {
        private final InputStream stream;
        private int current;
        private int size;
        private byte[] buffer = new byte[1024 * 8];

        public FastReader(InputStream stream) {
            this.stream = stream;
            current = 0;
            size = 0;
        }

        public int readInt() {
            int sign = 1;
            int abs = 0;
            int c = readNonEmpty();
            if (c == '-') {
                sign = -1;
                c = readAny();
            }
            do {
                if (c < '0' || c > '9') {
                    throw new IllegalStateException();
                }
                abs = 10 * abs + (c - '0');
                c = readAny();
            } while (!isEmpty(c));
            return sign * abs;
        }

        public int[] readIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0 ; i < n ; i++) {
                array[i] = readInt();
            }
            return array;
        }

        public char readChar() {
            return (char) readNonEmpty();
        }

        public String readString() {
            StringBuffer sb = new StringBuffer();
            int c;
            do {
                c = readAny();
            } while (isEmpty(c));
            do {
                sb.append((char) c);
                c = readAny();
            } while (!isEmpty(c));
            return sb.toString();
        }

        private int readAny() {
            try {
                if (current >= size) {
                    current = 0;
                    size = stream.read(buffer);
                    if (size < 0) {
                        return -1;
                    }
                }
            } catch (IOException e) {
                throw new RuntimeException("Failed to readAny next byte", e);
            }
            return buffer[current++];
        }

        private int readNonEmpty() {
            int result;
            do {
                result = readAny();
            } while (isEmpty(result));
            return result;
        }

        private static boolean isEmpty(int c) {
            return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == -1;
        }
    }
}

import java.awt.Point;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;

public class E {

	static int[][] dir = { { 1, 0 }, { 0, 1 }, { -1, 0 }, { 0, -1 } };

	static char[][] m;
	static int id[][], s[][], n, k, maxArea;
	static HashMap<Integer, Integer> w;

	static int bfs(int r, int c) {
		int count = 1;
		int myid = w.size() + 1;
		id[r][c] = myid;
		Queue<Point> q = new LinkedList<>();
		Point p = new Point(r, c);
		q.offer(p);
		while (!q.isEmpty()) {
			p = q.poll();
			for (int[] d : dir) {
				if (p.x + d[0] >= 0 && p.x + d[0] < n && p.y + d[1] >= 0 && p.y + d[1] < n
						&& id[p.x + d[0]][p.y + d[1]] == 0 && m[p.x + d[0]][p.y + d[1]] == '.') {
					id[p.x + d[0]][p.y + d[1]] = myid;
					count++;
					q.add(new Point(p.x + d[0], p.y + d[1]));
				}
			}
		}
		maxArea = Math.max(maxArea, count);
		w.put(myid, count);
		return count;
	}

	static boolean check(int r, int c, int dr, int dc) {
		if (r + dr < 0 || r + dr >= n || c + dc < 0 || c + dc >= n || id[r + dr][c + dc] == 0)
			return false;
		return true;
	}

	public static void main(String[] args) throws IOException {
		File inputFile = new File("entradaE");
		if (inputFile.exists())
			System.setIn(new FileInputStream(inputFile));
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder out = new StringBuilder();
		String line = "";
		while ((line = in.readLine()) != null) {
			int[] nk = readInts(line);
			n = nk[0];
			k = nk[1];
			m = new char[n][n];
			id = new int[n][n];
			s = new int[n][n];
			w = new HashMap<>(n * n);
			for (int i = 0; i < n; i++) {
				m[i] = in.readLine().toCharArray();
				for (int j = 0; j < n; j++) {
					s[i][j] = m[i][j] == '.' ? 1 : 0;
					s[i][j] += (i - 1 >= 0) ? s[i - 1][j] : 0;
					s[i][j] += (j - 1 >= 0) ? s[i][j - 1] : 0;
					s[i][j] -= (i - 1 >= 0 && j - 1 >= 0) ? s[i - 1][j - 1] : 0;
				}
			}
			maxArea = 0;
			for (int i = 0; i < n; i++)
				for (int j = 0; j < n; j++)
					if (m[i][j] == '.' && id[i][j] == 0)
						bfs(i, j);
			w.put(0, 0);
			boolean[] ids = new boolean[w.size()];
			int theid = 0, cur, inside = 0;
			for (int i = 0; i <= n - k; i++) {
				for (int j = 0; j <= n - k; j++) {
					Arrays.fill(ids, false);
					cur = 0;
					inside = s[i + k - 1][j + k - 1];
					inside += (i - 1 >= 0 && j - 1 >= 0) ? s[i - 1][j - 1] : 0;
					inside -= (i - 1 >= 0) ? s[i - 1][j + k - 1] : 0;
					inside -= (j - 1 >= 0) ? s[i + k - 1][j - 1] : 0;
					// Up
					for (int l = 0; l < k; l++)
						if (check(i, j + l, -1, 0)) {
							theid = id[i - 1][j + l];
							if (!ids[theid]) {
								ids[theid] = true;
								cur += w.get(theid);
							}
						}
					// Down
					for (int l = 0; l < k; l++)
						if (check(i + k - 1, j + l, 1, 0)) {
							theid = id[i + k][j + l];
							if (!ids[theid]) {
								ids[theid] = true;
								cur += w.get(theid);
							}
						}
					// Left
					for (int l = 0; l < k; l++)
						if (check(i + l, j, 0, -1)) {
							theid = id[i + l][j - 1];
							if (!ids[theid]) {
								ids[theid] = true;
								cur += w.get(theid);
							}
						}
					// Right
					for (int l = 0; l < k; l++)
						if (check(i + l, j + k - 1, 0, 1)) {
							theid = id[i + l][j + k];
							if (!ids[theid]) {
								ids[theid] = true;
								cur += w.get(theid);
							}
						}
					maxArea = Math.max(maxArea, cur - inside + k * k);
				}
			}
			out.append(maxArea + "\n");
		}
		System.out.print(out);
	}

	static int[] readInts(String line) {
		StringTokenizer st = new StringTokenizer(line.trim());
		int a[] = new int[st.countTokens()], index = 0;
		while (st.hasMoreTokens())
			a[index++] = Integer.parseInt(st.nextToken());
		return a;
	}

	static long[] readLongs(String line) {
		StringTokenizer st = new StringTokenizer(line.trim());
		long a[] = new long[st.countTokens()];
		int index = 0;
		while (st.hasMoreTokens())
			a[index++] = Long.parseLong(st.nextToken());
		return a;
	}

	static double[] readDoubles(String line) {
		StringTokenizer st = new StringTokenizer(line.trim());
		double a[] = new double[st.countTokens()];
		int index = 0;
		while (st.hasMoreTokens())
			a[index++] = Double.parseDouble(st.nextToken());
		return a;
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;

public class ProblemC {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		FastScanner input = new FastScanner();
		int n = input.nextInt();
		int limak = input.nextInt();
		int limakFoot = limak * limak;
		char[][] in = new char[n][n];
		for (int a = 0; a < n; a++) {
			in[a] = input.next().toCharArray();
		}
		// Our graph is implicit, so we don't actually need to store the graph.

		// First, we need to do connected components.
		int[][] componentId = new int[n][n];
		for (int a = 0; a < n; a++) {
			for (int b = 0; b < n; b++) {
				componentId[a][b] = -1;
			}
		}
		ArrayList<Integer> componentSizes = new ArrayList<Integer>();
		int component = 0;
		for (int a = 0; a < n; a++) {
			for (int b = 0; b < n; b++) {
				int num = bfs(a, b, in, componentId, component);
				if (num > 0) {
					component++;
					componentSizes.add(num);
				}
			}
		}
		// now we built our connected components
		// we are going to try every single possible bear location. We need to
		// be able to see how large of a connected component such a bear would
		// create.
		// n^3 is OK, n^4 is not. Therefore, we can do operations around the
		// perimiter of each possible spot, but not the area. My initial plan is
		// to go around the grid, and see what components are going inside.
		// Then, take the sum of those components (O(n)), and then do prefix
		// sums to get the number of 'wall' squares inside the grid. (O(n)).
		// Unfortunately, this doesn't handle if there is a connected component
		// entirely hidden under the bear's foot.
		// Could we do dynamic programming? When we start, we could have a
		// hashmap of what is under the foot, and then add/remove such things as
		// we 'move' the foot. This would be O(n) for each move, O(n) to count
		// the components, but it would be O(n^2) on the starting point.
		int bestAnswer = limak * limak;
		for (int a = 0; a < n - limak + 1; a++) {
			// these are all the starting 'x' coordinates
			int b = 0;
			BearFoot foot = startBear(a, b, limak, componentId, componentSizes);
			// startBear calculates what is under the bear's foot.
			for (; b < n - limak + 1; b++) {
				System.out.println("(" + a + ", " + b + ") " + foot);
				int answer = bearWithMe(foot);
				if (answer > bestAnswer) {
					bestAnswer = answer;
				}
				if (b != n - limak) {
					moveBear(foot, a, b, limak, componentId, componentSizes);
				}
			}
		}
		System.out.println(bestAnswer);
	}

	private static void moveBear(BearFoot foot, int a, int b, int limak,
			int[][] componentId, ArrayList<Integer> componentSizes) {
		// TODO Auto-generated method stub
		for (int c = 0; c < limak; c++) {
			if (componentId[a + c][b] < 0) {
				foot.footStomp--;
			}
		}
		for (int c = -1; c < limak + 1; c++) {
			try {
				if (componentId[a + c][b - 1] >= 0) {
					foot.componentFreq[componentId[a + c][b - 1]]--;
					if (foot.componentFreq[componentId[a + c][b - 1]] == 0) {
						foot.componentSum -= componentSizes.get(componentId[a
								+ c][b - 1]);
					}
				}
			} catch (Exception e) {

			}
		}
		for (int c = 0; c < limak; c++) {
			if (componentId[a + c][b + limak] < 0) {
				foot.footStomp++;
			}
		}
		for (int c = -1; c < limak + 1; c++) {
			try {
				if (componentId[a + c][b + limak + 1] >= 0) {
					foot.componentFreq[componentId[a + c][b + limak + 1]]++;
					if (foot.componentFreq[componentId[a + c][b + limak + 1]] == 1) {
						foot.componentSum += componentSizes.get(componentId[a
								+ c][b + limak + 1]);
					}
				}
			} catch (Exception e) {

			}
		}
	}

	private static int bearWithMe(BearFoot foot) {
		// TODO Auto-generated method stub
		return foot.componentSum + foot.footStomp;
	}

	private static BearFoot startBear(int a, int b, int limak,
			int[][] componentId, ArrayList<Integer> componentSizes) {
		// TODO Auto-generated method stub
		int[] componentFreq = new int[componentSizes.size()];
		int footStomp = 0;
		for (int aS = a; aS < a + limak; aS++) {
			for (int bS = b; bS < b + limak; bS++) {
				if (componentId[aS][bS] < 0) {
					footStomp++;
				}
			}
		}
		for (int aS = a - 1; aS < a + limak + 1; aS++) {
			for (int bS = b - 1; bS < b + limak + 1; bS++) {
				boolean aIsBound = aS == a - 1 || aS == a + limak;
				boolean bIsBound = bS == b - 1 || bS == b + limak;
				if (aIsBound && bIsBound) {

				} else {
					try {
						if (componentId[aS][bS] >= 0) {
							componentFreq[componentId[aS][bS]]++;
						}
					} catch (Exception e) {

					}
				}
			}
		}
		int componentSum = 0;
		for (int c = 0; c < componentFreq.length; c++) {
			if (componentFreq[c] > 0) {
				componentSum += componentSizes.get(c);
			}
		}

		return new BearFoot(componentSum, footStomp, componentFreq);
	}

	public static class BearFoot {
		int componentSum;
		int footStomp;
		int[] componentFreq;

		public BearFoot(int _componentSum, int _footStomp, int[] _componentFreq) {
			componentSum = _componentSum;
			footStomp = _footStomp;
			componentFreq = _componentFreq;
		}

		public String toString() {
			return componentSum + " " + footStomp + " "
					+ Arrays.toString(componentFreq);
		}
	}

	private static int bfs(int a, int b, char[][] in, int[][] componentId,
			int component) {
		if (illegalBound(a, b, in) || in[a][b] == 'X'
				|| componentId[a][b] != -1) {
			return 0;
		}
		componentId[a][b] = component;
		int up = bfs(a - 1, b, in, componentId, component);
		int down = bfs(a + 1, b, in, componentId, component);
		int right = bfs(a, b + 1, in, componentId, component);
		int left = bfs(a, b - 1, in, componentId, component);
		return up + down + right + left + 1;
	}

	private static boolean illegalBound(int a, int b, char[][] in) {
		return a < 0 || a >= in.length || b < 0 || b >= in[0].length;
	}

	public static class Point {
		int x;
		int y;

		public Point(int _x, int _y) {
			x = _x;
			y = _y;
		}
	}

	// FASTSCANNER2016
	public static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(Reader in) {
			br = new BufferedReader(in);
		}

		public FastScanner() {
			this(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		// Slightly different from java.util.Scanner.nextLine(),
		// which returns any remaining characters in current line,
		// if any.
		String readNextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;

public class ProblemC {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		FastScanner input = new FastScanner();
		int n = input.nextInt();
		int limak = input.nextInt();
		int limakFoot = limak * limak;
		char[][] in = new char[n][n];
		for (int a = 0; a < n; a++) {
			in[a] = input.next().toCharArray();
		}
		// Our graph is implicit, so we don't actually need to store the graph.

		// First, we need to do connected components.
		int[][] componentId = new int[n][n];
		for (int a = 0; a < n; a++) {
			for (int b = 0; b < n; b++) {
				componentId[a][b] = -1;
			}
		}
		ArrayList<Integer> componentSizes = new ArrayList<Integer>();
		int component = 0;
		for (int a = 0; a < n; a++) {
			for (int b = 0; b < n; b++) {
				int num = bfs(a, b, in, componentId, component);
				if (num > 0) {
					component++;
					componentSizes.add(num);
				}
			}
		}
		// now we built our connected components
		// we are going to try every single possible bear location. We need to
		// be able to see how large of a connected component such a bear would
		// create.
		// n^3 is OK, n^4 is not. Therefore, we can do operations around the
		// perimiter of each possible spot, but not the area. My initial plan is
		// to go around the grid, and see what components are going inside.
		// Then, take the sum of those components (O(n)), and then do prefix
		// sums to get the number of 'wall' squares inside the grid. (O(n)).
		// Unfortunately, this doesn't handle if there is a connected component
		// entirely hidden under the bear's foot.
		// Could we do dynamic programming? When we start, we could have a
		// hashmap of what is under the foot, and then add/remove such things as
		// we 'move' the foot. This would be O(n) for each move, O(n) to count
		// the components, but it would be O(n^2) on the starting point.
		int bestAnswer = limak * limak;
		for (int a = 0; a < n - limak + 1; a++) {
			// these are all the starting 'x' coordinates
			int b = 0;
			BearFoot foot = startBear(a, b, limak, componentId, componentSizes);
			// startBear calculates what is under the bear's foot.
			for (; b < n - limak + 1; b++) {
//				System.out.println("(" + a + ", " + b + ") " + foot);
				int answer = bearWithMe(foot);
				if (answer > bestAnswer) {
					bestAnswer = answer;
				}
				if (b != n - limak) {
					moveBear(foot, a, b, limak, componentId, componentSizes);
				}
			}
		}
		System.out.println(bestAnswer);
	}

	private static void moveBear(BearFoot foot, int a, int b, int limak,
			int[][] componentId, ArrayList<Integer> componentSizes) {
		// TODO Auto-generated method stub
		for (int c = 0; c < limak; c++) {
			if (componentId[a + c][b] < 0) {
				foot.footStomp--;
			}
		}
		for (int c = -1; c < limak + 1; c++) {
			try {
				if (componentId[a + c][b - 1] >= 0) {
					foot.componentFreq[componentId[a + c][b - 1]]--;
					if (foot.componentFreq[componentId[a + c][b - 1]] == 0) {
						foot.componentSum -= componentSizes.get(componentId[a
								+ c][b - 1]);
					}
				}
			} catch (Exception e) {

			}
		}
		for (int c = 0; c < limak; c++) {
			if (componentId[a + c][b + limak] < 0) {
				foot.footStomp++;
			}
		}
		for (int c = -1; c < limak + 1; c++) {
			try {
				if (componentId[a + c][b + limak + 1] >= 0) {
					foot.componentFreq[componentId[a + c][b + limak + 1]]++;
					if (foot.componentFreq[componentId[a + c][b + limak + 1]] == 1) {
						foot.componentSum += componentSizes.get(componentId[a
								+ c][b + limak + 1]);
					}
				}
			} catch (Exception e) {

			}
		}
	}

	private static int bearWithMe(BearFoot foot) {
		// TODO Auto-generated method stub
		return foot.componentSum + foot.footStomp;
	}

	private static BearFoot startBear(int a, int b, int limak,
			int[][] componentId, ArrayList<Integer> componentSizes) {
		// TODO Auto-generated method stub
		int[] componentFreq = new int[componentSizes.size()];
		int footStomp = 0;
		for (int aS = a; aS < a + limak; aS++) {
			for (int bS = b; bS < b + limak; bS++) {
				if (componentId[aS][bS] < 0) {
					footStomp++;
				}
			}
		}
		for (int aS = a - 1; aS < a + limak + 1; aS++) {
			for (int bS = b - 1; bS < b + limak + 1; bS++) {
				try{
					if (componentId[aS][bS] >= 0) {
						componentFreq[componentId[aS][bS]]++;
					}
				}
				catch(Exception e){

				}
			}
		}
		int componentSum = 0;
		for (int c = 0; c < componentFreq.length; c++) {
			if (componentFreq[c] > 0) {
				componentSum += componentSizes.get(c);
			}
		}

		return new BearFoot(componentSum, footStomp, componentFreq);
	}

	public static class BearFoot {
		int componentSum;
		int footStomp;
		int[] componentFreq;

		public BearFoot(int _componentSum, int _footStomp, int[] _componentFreq) {
			componentSum = _componentSum;
			footStomp = _footStomp;
			componentFreq = _componentFreq;
		}

		public String toString() {
			return componentSum + " " + footStomp + " "
					+ Arrays.toString(componentFreq);
		}
	}

	private static int bfs(int a, int b, char[][] in, int[][] componentId,
			int component) {
		if (illegalBound(a, b, in) || in[a][b] == 'X'
				|| componentId[a][b] != -1) {
			return 0;
		}
		componentId[a][b] = component;
		int up = bfs(a - 1, b, in, componentId, component);
		int down = bfs(a + 1, b, in, componentId, component);
		int right = bfs(a, b + 1, in, componentId, component);
		int left = bfs(a, b - 1, in, componentId, component);
		return up + down + right + left + 1;
	}

	private static boolean illegalBound(int a, int b, char[][] in) {
		return a < 0 || a >= in.length || b < 0 || b >= in[0].length;
	}

	public static class Point {
		int x;
		int y;

		public Point(int _x, int _y) {
			x = _x;
			y = _y;
		}
	}

	// FASTSCANNER2016
	public static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(Reader in) {
			br = new BufferedReader(in);
		}

		public FastScanner() {
			this(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		// Slightly different from java.util.Scanner.nextLine(),
		// which returns any remaining characters in current line,
		// if any.
		String readNextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

/**
 * Created by birukoudzmitry on 12.06.16.
 */

public class E {

    public static void main(String[] args){

        MyScanner in = new MyScanner();
        int n = in.nextInt();
        int k = in.nextInt();

        DisjointUnionSets dsu = new DisjointUnionSets(n*n);

        String[] field = new String[n];
        for(int i=0;i<n;++i){
            field[i] = in.next();
        }

        for(int i=0;i<n;++i){
            for(int j=0;j<n;++j){
                if(field[i].charAt(j)=='.'){
                    if(i>0&&field[i-1].charAt(j)=='.'){
                        dsu.union(i*n+j,(i-1)*n+j);
                    }
                    if(j>0&&field[i].charAt(j-1)=='.'){
                        dsu.union(i*n+j,i*n+j-1);
                    }
                }
            }
        }

        int result = 0;

        int[] components = new int[n*n];

        int dots = 0;

        int[][] dt = new int[n-k+1][n-k+1];

        for(int i=0;i<=n-k;++i){
            int except = 0;
            Arrays.fill(components,0);
            for(int j=0;j<=n-k;++j){
                int allDots = 0;
                Set<Integer> used = new HashSet<>();
                for(int i1=i;i1<i+k;i1++){
                    if(j-1>=0&&field[i1].charAt(j-1)=='.'){
                        allDots+=getDots(used,dsu,i1*n+j-1);
                    }
                    if(j+k<n&&field[i1].charAt(j+k)=='.'){
                        allDots+=getDots(used,dsu,i1*n+j+k);
                    }
                }

                for(int j1=j;j1<j+k;j1++){
                    if(i-1>=0&&field[i-1].charAt(j1)=='.'){
                        allDots+=getDots(used,dsu,(i-1)*n+j1);
                    }
                    if(i+k<n&&field[i+k].charAt(j1)=='.'){
                        allDots+=getDots(used,dsu,(i+k)*n+j1);
                    }
                }

                if(i==0&&j==0){
                    for(int i1=i;i1<i+k;i1++){
                        for(int j1=j;j1<j+k;j1++){
                            if(field[i1].charAt(j1)=='.'){
                                components[dsu.find(i1*n+j1)]++;
                                dots++;
                                if(components[dsu.find(i1*n+j1)]==dsu.size[dsu.find(i1*n+j1)]){
                                    except+=components[dsu.find(i1*n+j1)];
                                }
                            }
                        }
                    }
                    dt[0][0] = dots;
                }else{
                    int newDots = 0;
                    int oldDots = 0;
                    if(j==0){
                        dots = dt[i-1][j];
                        for(int j1=j;j1<j+k;++j1){
                            if(field[i-1].charAt(j1)=='.'){
                                if(components[dsu.find((i-1)*n+j1)]==dsu.size[dsu.find((i-1)*n+j1)]){
                                    except-=dsu.size[dsu.find((i-1)*n+j1)];
                                }
                                components[dsu.find((i-1)*n+j1)]--;
                                oldDots++;
                            }
                        }
                        for(int j1=j;j1<j+k;++j1){
                            if(field[i+k-1].charAt(j1)=='.'){
                                components[dsu.find((i+k-1)*n+j1)]++;
                                if(components[dsu.find((i+k-1)*n+j1)]==dsu.size[dsu.find((i+k-1)*n+j1)]){
                                    except+=components[dsu.find((i+k-1)*n+j)];
                                }
                                newDots++;
                            }
                        }
                    }else{
                        for(int i1=i;i1<i+k;++i1){
                            if(field[i1].charAt(j-1)=='.'){
                                if(components[dsu.find(i1*n+j-1)]==dsu.size[dsu.find(i1*n+j-1)]){
                                    except-=dsu.size[dsu.find(i1*n+j-1)];
                                }
                                components[dsu.find(i1*n+j-1)]--;
                                oldDots++;
                            }
                        }
                        for(int i1=i;i1<i+k;++i1){
                            if(field[i1].charAt(j+k-1)=='.'){
                                components[dsu.find(i1*n+j+k-1)]++;
                                if(components[dsu.find(i1*n+j+k-1)]==dsu.size[dsu.find(i1*n+j+k-1)]){
                                    except+=components[dsu.find(i1*n+j+k-1)];
                                }
                                newDots++;
                            }
                        }
                    }
                    dots+=(newDots-oldDots);
                    dt[i][j] = dots;
                }

//                if(allDots+k*k-dots+except>result){
//                    System.out.println(i+" , "+j);
//                    System.out.println(allDots+k*k-dots+except);
//                }
                result = Math.max(result,allDots+k*k-dots+except);
            }
        }
        System.out.println(result);
    }

    private static int getDots(Set<Integer> used, DisjointUnionSets dsu, int index) {
        if(!used.contains(dsu.find(index))){
            used.add(dsu.find(index));
            return dsu.size[dsu.find(index)];
        }
        return 0;
    }

    static class DisjointUnionSets
    {
        int[] rank, parent,size;
        int n;

        // Constructor
        public DisjointUnionSets(int n)
        {
            size = new int[n];
            rank = new int[n];
            parent = new int[n];
            this.n = n;
            makeSet();
        }

        // Creates n sets with single item in each
        void makeSet()
        {
            for (int i=0; i<n; i++)
            {
                // Initially, all elements are in
                // their own set.
                parent[i] = i;
                size[i] = 1;
            }
        }

        // Returns representative of x's set
        int find(int x)
        {
            // Finds the representative of the set
            // that x is an element of
            if (parent[x]!=x)
            {
                // if x is not the parent of itself
                // Then x is not the representative of
                // his set,
                parent[x] = find(parent[x]);

                // so we recursively call Find on its parent
                // and move i's node directly under the
                // representative of this set
            }

            return parent[x];
        }

        // Unites the set that includes x and the set
        // that includes x
        void union(int x, int y)
        {
            // Find representatives of two sets
            int xRoot = find(x), yRoot = find(y);

            // Elements are in the same set, no need
            // to unite anything.
            if (xRoot == yRoot)
                return;

            // If x's rank is less than y's rank
            if (rank[xRoot] < rank[yRoot]) {

                // Then move x under y  so that depth
                // of tree remains less
                parent[xRoot] = yRoot;
                size[yRoot] += size[xRoot];
                // Else if y's rank is less than x's rank
            }else if (rank[yRoot] < rank[xRoot]) {

                // Then move y under x so that depth of
                // tree remains less
                parent[yRoot] = xRoot;
                size[xRoot] += size[yRoot];

            }else // if ranks are the same
            {
                // Then move y under x (doesn't matter
                // which one goes where)
                parent[yRoot] = xRoot;
                size[xRoot]+=size[yRoot];
                // And increment the the result tree's
                // rank by 1
                rank[xRoot] = rank[xRoot] + 1;
            }
        }
    }

    // -----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
    // --------------------------------------------------------

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.StringTokenizer;

/**
 * Created by birukoudzmitry on 12.06.16.
 */

public class E {

    public static void main(String[] args){

        MyScanner in = new MyScanner();
        int n = in.nextInt();
        int k = in.nextInt();

        DisjointUnionSets dsu = new DisjointUnionSets(n*n);

        String[] field = new String[n];
        for(int i=0;i<n;++i){
            field[i] = in.next();
        }

        for(int i=0;i<n;++i){
            for(int j=0;j<n;++j){
                if(field[i].charAt(j)=='.'){
                    if(i>0&&field[i-1].charAt(j)=='.'){
                        dsu.union(i*n+j,(i-1)*n+j);
                    }
                    if(j>0&&field[i].charAt(j-1)=='.'){
                        dsu.union(i*n+j,i*n+j-1);
                    }
                }
            }
        }

        int result = 0;

        for(int i=0;i<=n-k;++i){
            int dots = 0;
            for(int j=0;j<=n-k;++j){
                int allDots = 0;
                Set<Integer> used = new HashSet<>();
                for(int i1=i;i1<i+k;i1++){
                    if(j-1>=0&&field[i1].charAt(j-1)=='.'){
                        allDots+=getDots(used,dsu,i1*n+j-1);
                    }
                    if(j+k<n&&field[i1].charAt(j+k)=='.'){
                        allDots+=getDots(used,dsu,i1*n+j+k);
                    }
                }

                for(int j1=j;j1<j+k;j1++){
                    if(i-1>=0&&field[i-1].charAt(j1)=='.'){
                        allDots+=getDots(used,dsu,(i-1)*n+j1);
                    }
                    if(i+1<n&&field[i+1].charAt(j1)=='.'){
                        allDots+=getDots(used,dsu,(i+1)*n+j1);
                    }
                }

                if(j==0){
                    for(int i1=i;i1<i+k;i1++){
                        for(int j1=j;j1<j+k;j1++){
                            if(field[i1].charAt(j1)=='.'&&used.contains(dsu.find(i1*n+j1))){
                                dots++;
                            }
                        }
                    }
                }else{
                    int newDots = 0;
                    int oldDots = 0;
                    for(int i1=i;i1<i+k;++i1){
                        if(field[i1].charAt(j-1)=='.'&&used.contains(dsu.find(i1*n+j-1))){
                            oldDots++;
                        }
                        if(field[i1].charAt(j+k-1)=='.'&&used.contains(dsu.find(i1*n+j+k-1))){
                            newDots++;
                        }
                    }
                    dots+=(newDots-oldDots);
                }

//                if(allDots+k*k-dots>result){
//                    System.out.println(allDots+k*k-dots);
//                    System.out.println(i+" , "+j);
//                }
                result = Math.max(result,allDots+k*k-dots);
            }
        }
        System.out.println(result);
    }

    private static int getDots(Set<Integer> used, DisjointUnionSets dsu, int index) {
        if(!used.contains(dsu.find(index))){
            used.add(dsu.find(index));
            return dsu.size[dsu.find(index)];
        }
        return 0;
    }

    static class DisjointUnionSets
    {
        int[] rank, parent,size;
        int n;

        // Constructor
        public DisjointUnionSets(int n)
        {
            size = new int[n];
            rank = new int[n];
            parent = new int[n];
            this.n = n;
            makeSet();
        }

        // Creates n sets with single item in each
        void makeSet()
        {
            for (int i=0; i<n; i++)
            {
                // Initially, all elements are in
                // their own set.
                parent[i] = i;
                size[i] = 1;
            }
        }

        // Returns representative of x's set
        int find(int x)
        {
            // Finds the representative of the set
            // that x is an element of
            if (parent[x]!=x)
            {
                // if x is not the parent of itself
                // Then x is not the representative of
                // his set,
                parent[x] = find(parent[x]);

                // so we recursively call Find on its parent
                // and move i's node directly under the
                // representative of this set
            }

            return parent[x];
        }

        // Unites the set that includes x and the set
        // that includes x
        void union(int x, int y)
        {
            // Find representatives of two sets
            int xRoot = find(x), yRoot = find(y);

            // Elements are in the same set, no need
            // to unite anything.
            if (xRoot == yRoot)
                return;

            // If x's rank is less than y's rank
            if (rank[xRoot] < rank[yRoot]) {

                // Then move x under y  so that depth
                // of tree remains less
                parent[xRoot] = yRoot;
                size[yRoot] += size[xRoot];
                // Else if y's rank is less than x's rank
            }else if (rank[yRoot] < rank[xRoot]) {

                // Then move y under x so that depth of
                // tree remains less
                parent[yRoot] = xRoot;
                size[xRoot] += size[yRoot];

            }else // if ranks are the same
            {
                // Then move y under x (doesn't matter
                // which one goes where)
                parent[yRoot] = xRoot;
                size[xRoot]+=size[yRoot];
                // And increment the the result tree's
                // rank by 1
                rank[xRoot] = rank[xRoot] + 1;
            }
        }
    }

    // -----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
    // --------------------------------------------------------

}

import java.io.*;
import java.util.*;

public class E{
    static java.io.PrintStream out=System.out;
    void inc(int p){
        if(count[p]++==0)
            sum+=num.get(p);
    }
    void dec(int p){
        if(count[p]--==1)
            sum-=num.get(p);
    }
    int n, k;
    char[][] map;
    int sum;
    int[] count;
    int[][] ctgry;
    List<Integer> num;

    int[][] dir=new int[][]{{1,0},{-1,0},{0,1},{0,-1}};
    int dfs(int i, int j, boolean[][] visited, int N){
        visited[i][j]=true;
        ctgry[i][j]=N;
        int num=1;
        for(int k=0; k<4; k++){
            int x=i+dir[k][0], y=j+dir[k][1];
            if(x>=0 && x<n && y>=0 && y<n && map[x][y]=='.' && !visited[x][y])
                num+=dfs(x,y,visited,N);
        }
        return num;
    }
    boolean[] set;
    int solve(){
        boolean[][] visited=new boolean[n][n];
        int N=0;

        ctgry=new int[n][n];
        num=new ArrayList<>();

        for(int i=0; i<n; i++)
            for(int j=0; j<n; j++)
                if(map[i][j]=='.' && !visited[i][j]){
                    num.add(dfs(i,j,visited,N));
                    N++;
                }else if(map[i][j]=='X'){
                    ctgry[i][j]=N;
                    num.add(1);
                    N++;
                }

        count=new int[N];
        set=new boolean[N];
        sum=0;
        for(int i=0; i<k; i++)
            for(int j=0; j<k; j++)
                inc(ctgry[i][j]);
        int max=getSum(0,0);

        for(int i=0; i<=n-k;i++){
            for(int j=i%2==1?(n-k-1):1, jj=0;
                    jj<n-k; j+=(i%2==1?-1:1), jj++){
                for(int l=i; l<i+k; l++){
                    if(i%2==0){
                        inc(ctgry[l][j+k-1]);
                        dec(ctgry[l][j-1]);
                    }else{
                        inc(ctgry[l][j]);
                        dec(ctgry[l][j+k]);
                    }
                }
                max=Math.max(max,getSum(i,j));
            }
            if(i>=n-k) break;

            int j=i%2==0?n-k:0;
            for(int l=j; l<j+k; l++){
                inc(ctgry[i+k][l]);
                dec(ctgry[i][l]);
            }
            max=Math.max(max,getSum(i,j));
        }
        return max;
    }
    private int getSum(int i, int j){
        Arrays.fill(set,false);
        int s=sum, pp;
        if(i-->0) for(int l=j; l<j+k; l++)
            if(!set[pp=ctgry[i][l]] && map[i][l]=='.' && count[(pp)]==0){
                //out.println(pp+" "+uf.size[pp]);
                s+=num.get(pp);
                set[pp]=true;
            }
        i++;

        i+=k;
        if(i<n) for(int l=j; l<j+k; l++)
            if(!set[pp=ctgry[i][l]] && map[i][l]=='.' && count[(pp)]==0){
                s+=num.get(pp);
                set[pp]=true;
            }
        i-=k;

        j--;
        if(j>=0) for(int l=i; l<i+k; l++)
            if(!set[pp=ctgry[i][l]] && map[i][l]=='.' && count[(pp)]==0){
                s+=num.get(pp);
                set[pp]=true;
            }
        j++;
        j+=k;
        if(j<n) for(int l=i; l<i+k; l++)
            if(!set[pp=ctgry[i][l]] && map[i][l]=='.' && count[(pp)]==0){
                s+=num.get(pp);
                set[pp]=true;
            }
        //out.format("i=%d, j=%d, sum=%d, s=%d\n", i,j,sum,s);
        return s;
    }
    public static void main(String[] argin) {
        E inst = new E();
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()){
            int n = in.nextInt(), k=in.nextInt();
            char[][] map = new char[n][];
            for(int i=0; i<n; i++)
                map[i]=in.next().toCharArray();
            inst.map=map;
            inst.n=n;
            inst.k=k;
            out.println(inst.solve());
        }
    }
}

import java.io.*;
import java.util.*;

public class E{
    class UnionFind{
        int[] p, size;
        int comps;
        int max;
        UnionFind(int n){
            p = new int[n];
            size = new int[n];
            reset();
        }
        UnionFind(UnionFind old){
            p = old.p.clone();
            size = old.size.clone();
            comps=old.comps;
            max=old.max;
        }
        void reset(){
            for(int i=0; i<p.length; i++){
                p[i]=i;
                size[i]=1;
            }
            comps = p.length;
            max=1;
        }
        int find(int x){
            if(x!=p[x]) p[x]=find(p[x]);
            return p[x];
        }
        void union(int x, int y){
            x = find(x);
            y = find(y);
            if(x!=y)
                if(size[x]>size[y]){
                    p[y]=x;
                    size[x]+=size[y];
                    max=Math.max(max,size[x]);
                }else{
                    p[x]=y;
                    size[y]+=size[x];
                    max=Math.max(max,size[y]);
                }
            comps--;
        }
    }
    static java.io.PrintStream out=System.out;
    int solve(int n, int k, char[][] map){
        UnionFind uf=new UnionFind(n*n);
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                if(i>0 && map[i][j]=='.' && map[i-1][j]=='.')
                    uf.union(i*n+j,(i-1)*n+j);
                if(j>0 && map[i][j]=='.' && map[i][j-1]=='.')
                    uf.union(i*n+j,i*n+j-1);
            }
        }
        int max=0;
        for(int i=0; i<n-k; i++)
            for(int j=0; j<n-k; j++){
                UnionFind bak=new UnionFind(uf);
                for(int x=i; x<i+k; x++)
                    for(int y=j; y<j+k; y++){
                        if((x==i     && x-1>=0 && map[x-1][y]=='.') || x>i)     bak.union(x*n+y,(x-1)*n+y);
                        if((y==j     && y-1>=0 && map[x][y-1]=='.') || y>j)     bak.union(x*n+y,x*n+y-1);
                        if((x==i+k-1 && x+1<n  && map[x+1][y]=='.') || x<i+k-1) bak.union(x*n+y,(x+1)*n+y);
                        if((y==j+k-1 && y+1<n  && map[x][y+1]=='.') || y<j+k-1) bak.union(x*n+y,x*n+y+1);
                    }
                max=Math.max(max,bak.max);
            }
        return max;
    }
    public static void main(String[] argin) {
        E inst = new E();
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()){
            int n = in.nextInt(), k=in.nextInt();
            char[][] map = new char[n][];
            for(int i=0; i<n; i++)
                map[i]=in.next().toCharArray();
            out.println(inst.solve(n,k,map));
        }
    }
}

import java.io.*;
import java.util.*;

public class E{
    static java.io.PrintStream out=System.out;
    void inc(int p){
        if(count[p]++==0)
            sum+=num.get(p);
    }
    void dec(int p){
        if(count[p]--==1)
            sum-=num.get(p);
    }
    int n, k;
    char[][] map;
    int sum;
    int[] count;
    int[][] ctgry;
    List<Integer> num;

    int[][] dir=new int[][]{{1,0},{-1,0},{0,1},{0,-1}};
    int dfs(int i, int j, boolean[][] visited, int N){
        visited[i][j]=true;
        ctgry[i][j]=N;
        int num=1;
        for(int k=0; k<4; k++){
            int x=i+dir[k][0], y=j+dir[k][1];
            if(x>=0 && x<n && y>=0 && y<n && map[x][y]=='.' && !visited[x][y])
                num+=dfs(x,y,visited,N);
        }
        return num;
    }
    boolean[] set;
    int solve(){
        boolean[][] visited=new boolean[n][n];
        int N=0;

        ctgry=new int[n][n];
        num=new ArrayList<>();

        for(int i=0; i<n; i++)
            for(int j=0; j<n; j++)
                if(map[i][j]=='.' && !visited[i][j]){
                    num.add(dfs(i,j,visited,N));
                    N++;
                }else if(map[i][j]=='X'){
                    ctgry[i][j]=N;
                    num.add(1);
                    N++;
                }

        count=new int[N];
        set=new boolean[N];
        sum=0;
        for(int i=1; i<=k; i++)
            for(int j=1; j<=k; j++)
                inc(ctgry[i][j]);
        int max=getSum(0,0);

        for(int i=1; i<n-k;i++){
            for(int j=i%2==1?(n-k-2):2, jj=0;
                    jj<n-k-2; j+=(i%2==1?-1:1), jj++){
                for(int l=i; l<i+k; l++){
                    if(i%2==0){
                        inc(ctgry[l][j+k-1]);
                        dec(ctgry[l][j-1]);
                    }else{
                        inc(ctgry[l][j]);
                        dec(ctgry[l][j+k]);
                    }
                }
                max=Math.max(max,getSum(i,j));
            }
            if(i>=n-k) break;

            int j=i%2==0?n-k:0;
            for(int l=j; l<j+k; l++){
                inc(ctgry[i+k][l]);
                dec(ctgry[i][l]);
            }
            max=Math.max(max,getSum(i,j));
        }
        return max;
    }
    private int getSum(int i, int j){
        Arrays.fill(set,false);
        int s=sum, pp;
        if(i-->0) for(int l=j; l<j+k; l++)
            if(map[i][l]=='.' && count[(pp=ctgry[i][l])]==0 && !set[pp]){
                //out.println(pp+" "+uf.size[pp]);
                s+=num.get(pp);
                set[pp]=true;
            }
        i++;

        i+=k;
        if(i<n) for(int l=j; l<j+k; l++)
            if(map[i][l]=='.' && count[(pp=ctgry[i][l])]==0 && !set[pp]){
                s+=num.get(pp);
                set[pp]=true;
            }
        i-=k;

        j--;
        if(j>=0) for(int l=i; l<i+k; l++)
            if(map[l][j]=='.' && count[(pp=ctgry[l][j])]==0 && !set[pp]){
                s+=num.get(pp);
                set[pp]=true;
            }
        j++;
        j+=k;
        if(j<n) for(int l=i; l<i+k; l++)
            if(map[l][j]=='.' && count[(pp=ctgry[l][j])]==0 && !set[pp]){
                s+=num.get(pp);
                set[pp]=true;
            }
        //out.format("i=%d, j=%d, sum=%d, s=%d\n", i,j,sum,s);
        return s;
    }
    public static void main(String[] argin) {
        E inst = new E();
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()){
            int n = in.nextInt(), k=in.nextInt();
            char[][] map = new char[n][];
            for(int i=0; i<n; i++)
                map[i]=in.next().toCharArray();
            inst.map=map;
            inst.n=n;
            inst.k=k;
            out.println(inst.solve());
        }
    }
}

import java.io.*;
import java.util.*;

public class E{
    static java.io.PrintStream out=System.out;
    void inc(int p){
        if(count[p]++==0)
            sum+=num.get(p);
    }
    void dec(int p){
        if(count[p]--==1)
            sum-=num.get(p);
    }
    int n, k;
    char[][] map;
    int sum;
    int[] count;
    int[][] ctgry;
    List<Integer> num;

    int[][] dir=new int[][]{{1,0},{-1,0},{0,1},{0,-1}};
    int dfs(int i, int j, boolean[][] visited, int N){
        visited[i][j]=true;
        ctgry[i][j]=N;
        int num=1;
        for(int k=0; k<4; k++){
            int x=i+dir[k][0], y=j+dir[k][1];
            if(x>=0 && x<n && y>=0 && y<n && map[x][y]=='.' && !visited[x][y])
                num+=dfs(x,y,visited,N);
        }
        return num;
    }
    int solve(){
        boolean[][] visited=new boolean[n][n];
        int N=0;

        ctgry=new int[n][n];
        num=new ArrayList<>();

        for(int i=0; i<n; i++)
            for(int j=0; j<n; j++)
                if(map[i][j]=='.' && !visited[i][j]){
                    num.add(dfs(i,j,visited,N));
                    N++;
                }else if(map[i][j]=='X'){
                    ctgry[i][j]=N;
                    num.add(1);
                    N++;
                }

        count=new int[N];
        sum=0;
        for(int i=0; i<k; i++)
            for(int j=0; j<k; j++)
                inc(ctgry[i][j]);
        int max=getSum(0,0);

        for(int i=0; i<=n-k;i++){
            for(int j=i%2==1?(n-k-1):1, jj=0;
                    jj<n-k; j+=(i%2==1?-1:1), jj++){
                for(int l=i; l<i+k; l++){
                    if(i%2==0){
                        inc(ctgry[l][j+k-1]);
                        dec(ctgry[l][j-1]);
                    }else{
                        inc(ctgry[l][j]);
                        dec(ctgry[l][j+k]);
                    }
                }
                max=Math.max(max,getSum(i,j));
            }
            if(i>=n-k) break;

            int j=i%2==0?n-k:0;
            for(int l=j; l<j+k; l++){
                inc(ctgry[i+k][l]);
                dec(ctgry[i][l]);
            }
            max=Math.max(max,getSum(i,j));
        }
        return max;
    }
    private int getSum(int i, int j){
        Set<Integer> set=new HashSet<>();
        int s=sum, pp;
        for(int l=j; l<j+k; l++)
            for(int m=i-1, t=0; t<2 && m>=0 && m<n; m+=k+1, t++)
                if(!set.contains(pp=ctgry[m][l]) && map[m][l]=='.' && count[(pp)]==0){
                    //out.println(pp+" "+uf.size[pp]);
                    s+=num.get(pp);
                    set.add(pp);
                }

        for(int l=i; l<i+k; l++)
            for(int m=j-1, t=0; t<2 && m>=0 && m<n; m+=k+1, t++)
                if(!set.contains(pp=ctgry[l][m]) && map[l][m]=='.' && count[(pp)]==0){
                    s+=num.get(pp);
                    set.add(pp);
                }
        //out.format("i=%d, j=%d, sum=%d, s=%d\n", i,j,sum,s);
        return s;
    }
    public static void main(String[] argin) {
        E inst = new E();
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()){
            int n = in.nextInt(), k=in.nextInt();
            char[][] map = new char[n][];
            for(int i=0; i<n; i++)
                map[i]=in.next().toCharArray();
            inst.map=map;
            inst.n=n;
            inst.k=k;
            out.println(inst.solve());
        }
    }
}

import java.util.*;
public class ProE {
	static int n,k,ans,ct,kk,a,res;
	static String ss;
	static int[] mm=new int[250005];
	static int[] pp=new int[250005];
	static int[] qq=new int[250005];
	static char[][] map=new char[505][];
	static int[][] vis=new int[505][505];
	static int[] vx={0,0,1,-1},vy={1,-1,0,0};
	static void dfs(int x,int y)
	{
		vis[x][y]=kk;ct++;
		for(int i=0;i<4;i++)
		{
			int xx=x+vx[i],yy=y+vy[i];
			if(0<xx&&xx<=n&&0<yy&&yy<=n&&vis[xx][yy]==0&&map[xx][yy]!='X')
				dfs(xx,yy);
		}
	}

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		n=in.nextInt();k=in.nextInt();
		for(int i=1;i<=n;i++)
		{
			ss=" "+in.next();
			map[i]=ss.toCharArray();
		}
		for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
		{
			if(vis[i][j]==0&&map[i][j]!='X')
			{
				ct=0;kk++;
				dfs(i,j);mm[kk]=ct;
			}
		}
		ans=0;
		for(int i=1;i<=n-k+1;i++)
		{
			Arrays.fill(pp,0);
			for(int j=0;j<k;j++)
			for(int p=1;p<=k;p++)
			{
				if(map[i+j][p]=='X') continue;
				pp[vis[i+j][p]]++;
			}
			for(int j=1;j<=n-k+1;j++)
			{
				for(int p=0;p<k;p++)
				{
					a=vis[i-1][j+p];
					if(qq[a]==0) { qq[a]=1;res+=mm[a];res-=pp[a];}
					a=vis[i+k][j+p];
					if(qq[a]==0) { qq[a]=1;res+=mm[a];res-=pp[a];}
					a=vis[i+p][j-1];
					if(qq[a]==0) { qq[a]=1;res+=mm[a];res-=pp[a];}
					a=vis[i+p][j+k];
					if(qq[a]==0) { qq[a]=1;res+=mm[a];res-=pp[a];}
				}
				for(int p=0;p<k;p++)
				{
					qq[vis[i-1][j+p]]=0;
					qq[vis[i+k][j+p]]=0;
					qq[vis[i+p][j-1]]=0;
					qq[vis[i+p][j+k]]=0;
				}
				res+=k*k;
				ans=Math.max(ans,res);
				if(j==n-k+1) continue;
				for(int p=0;p<k;p++)
				{
					if(map[i+p][j]!='X')
						pp[vis[i+p][j]]--;
					if(map[i+p][j+k]!='X')
						pp[vis[i+p][j+k]]++;
				}
			}
		}
		System.out.println(ans);
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class A {

	static final int[] dx = { 0, 0, -1, 1 };
	static final int[] dy = { -1, 1, 0, 0 };
	static int[][] grid;
	static int N, cnt, inside[], size[];

	static boolean valid(int x, int y) { return x < N && y < N && x > -1 && y > -1 && grid[x][y] == 0; }

	static void dfs(int x, int y, int c)
	{
		grid[x][y] = c;
		size[c]++;
		for(int k = 0; k < 4; ++k)
		{
			int i = x + dx[k], j = y + dy[k];
			if(valid(i, j))
				dfs(i, j, c);
		}
	}

	static void add(int x) { if(inside[x]++ == 0) cnt += size[x]; }

	static void erase(int x) { if(inside[x]-- == 1) cnt -= size[x]; }

	public static void main(String[] args) throws IOException
	{
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		N = sc.nextInt();
		int k = sc.nextInt();
		grid = new int[N][N];
		for(int i = 0; i < N; ++i)
		{
			String s = sc.next();
			for(int j = 0; j < N; ++j)
				if(s.charAt(j) == 'X')
					grid[i][j] = -1;
				else
					grid[i][j] = 0;
		}
		int idx = 0;
		inside = new int[N * N + 1];
		size = new int[N * N + 1];
		for(int i = 0; i < N; ++i)
			for(int j = 0; j < N; ++j)
				if(grid[i][j] == 0)
					dfs(i, j, ++idx);

		for(int i = 0; i < k; ++i)
			for(int j = 0; j < k; ++j)
				if(grid[i][j] == -1)
					++cnt;
				else
					add(grid[i][j]);
		if(k == N)
			out.println(cnt);
		else
		{
			for(int i = 0; i < k; ++i)
			{
				if(grid[i][k] != -1)
					add(grid[i][k]);
				if(grid[k][i] != -1)
					add(grid[k][i]);
			}
			int ans = cnt, d = 1, sx = 0, sy = 0;
			while(true)
			{
				while(sy + d != -1 && sy + d + k <= N)
				{
					if(d == 1)
						goRight(sx, sy++, k);
					else
						goLeft(sx, sy--, k);
					ans = Math.max(ans, cnt);
				}
				if(sx + k == N)
					break;
				goDown(sx++, sy, k);
				ans = Math.max(ans, cnt);
				d *= -1;
			}
			out.println(ans);
		}
		out.flush();
		out.close();
	}

	static void goDown(int sx, int sy, int k)
	{
		if(sx != 0)
			for(int j = sy; j < sy + k; ++j)
				if(grid[sx - 1][j] != -1)
					erase(grid[sx - 1][j]);
		for(int j = sy; j < sy + k; ++j)
			if(grid[sx][j] == -1)
				--cnt;
		if(sy > 0 && grid[sx][sy - 1] != -1)
			erase(grid[sx][sy - 1]);
		if(sy + k < N && grid[sx][sy + k] != -1)
			erase(grid[sx][sy + k]);
		++sx;
		for(int j = sy; j < sy + k; ++j)
			if(grid[sx + k - 1][j] == -1)
				++cnt;
		if(sx + k < N)
			for(int j = sy; j < sy + k; ++j)
				if(grid[sx + k][j] != -1)
					add(grid[sx + k][j]);
		if(sy > 0 && grid[sx + k - 1][sy - 1] != -1)
			erase(grid[sx + k - 1][sy - 1]);
		if(sy + k < N && grid[sx + k - 1][sy + k] != -1)
			erase(grid[sx + k - 1][sy + k]);
	}

	static void goRight(int sx, int sy, int k)
	{
		if(sy != 0)
			for(int i = sx; i < sx + k; ++i)
				if(grid[i][sy - 1] != -1)
					erase(grid[i][sy - 1]);
		for(int i = sx; i < sx + k; ++i)
			if(grid[i][sy] == -1)
				--cnt;
		if(sx > 0 && grid[sx - 1][sy] != -1)
			erase(grid[sx - 1][sy]);
		if(sx + k < N && grid[sx + k][sy] != -1)
			erase(grid[sx + k][sy]);
		++sy;
		if(sy + k < N)
			for(int i = sx; i < sx + k; ++i)
				if(grid[i][sy + k] != -1)
					add(grid[i][sy + k]);
		for(int i = sx; i < sx + k; ++i)
			if(grid[i][sy + k - 1] == -1)
				++cnt;
		if(sx > 0 && grid[sx - 1][sy + k - 1] != -1)
			add(grid[sx - 1][sy + k - 1]);
		if(sx + k < N && grid[sx + k][sy + k - 1] != -1)
			add(grid[sx + k][sy + k - 1]);
	}

	static void goLeft(int sx, int sy, int k)
	{
		if(sy + k < N)
			for(int i = sx; i < sx + k; ++i)
				if(grid[i][sy + k] != -1)
					erase(grid[i][sy + k]);
		for(int i = sx; i < sx + k; ++i)
			if(grid[i][sy + k - 1] == -1)
				--cnt;
		if(sx > 0 && grid[sx - 1][sy + k - 1] != -1)
			erase(grid[sx - 1][sy + k - 1]);
		if(sx + k < N && grid[sx + k][sy + k - 1] != -1)
			erase(grid[sx + k][sy + k - 1]);
		--sy;
		if(sy != 0)
			for(int i = sx; i < sx + k; ++i)
				if(grid[i][sy - 1] != -1)
					add(grid[i][sy - 1]);
		for(int i = sx; i < sx + k; ++i)
			if(grid[i][sy] == -1)
				++cnt;
		if(sx > 0 && grid[sx - 1][sy] != -1)
			add(grid[sx - 1][sy]);
		if(sx + k < N && grid[sx + k][sy] != -1)
			add(grid[sx + k][sy]);
	}

	static class Scanner
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public String next() throws IOException
		{
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {return Integer.parseInt(next());}

		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}

		public double nextDouble() throws IOException { return Double.parseDouble(next()); }
	}
}

import java.util.*;
import java.io.*;
/*
5 3
.....
.XXX.
.XXX.
.XXX.
.....

 */
public class a
{
	public static void main(String[] args) throws IOException
	{
		new a();
	}
	int n;
	int k;
	String[] g;
	int[][] grid;
	boolean[][] used;
	ArrayList<Integer> cnt;
	int[] dr = new int[]{-1, 1, 0, 0};
	int[] dc = new int[]{0, 0, -1, 1};
	public a() throws IOException
	{
		FastScanner in = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		n = in.nextInt();
		k = in.nextInt();
		if(n == 1)
		{
			System.out.println(1);
		}
		else
		{
			g = new String[n];
			for(int i = 0; i < n; i++) g[i] = in.next();
			grid = new int[n][n];
			for(int[] a : grid) Arrays.fill(a, -1);
			used = new boolean[n][n];
			cnt = new ArrayList<Integer>();
			for(int i = 0; i < n; i++)
			{
				for(int j = 0; j < n; j++)
				{
					if(g[i].charAt(j) == '.' && !used[i][j])
					{
						used[i][j] = true;
						grid[i][j] = cnt.size();
						cnt.add(floodfill(i, j, cnt.size()));
					}
				}
			}

			long ret = 0;
			for(int i = 0; i < cnt.size(); i++) ret = Math.max(ret, cnt.get(i));
			ret = Math.max(ret, k*k);
			for(int i = 0; i <= n-k; i++)
			{
				int lp = 0;
				int rp = -1;
				int total = 0;
				int[] u = new int[cnt.size()];
				while(rp <= n-k)
				{
					rp++;
					if(rp >= n) break;
					for(int j = 0; j < k; j++)
					{
						if(g[i+j].charAt(rp) == 'X')
						{
							total++;
						}
						if(grid[i+j][rp] != -1)
						{
							int num = grid[i+j][rp];
							if(u[num] == 0)
							{
								total += cnt.get(num);
							}
							u[num]++;
						}
					}

					if(rp-lp+1 > k)
					{
						for(int j = 0; j < k; j++)
						{
							if(g[i+j].charAt(lp) == 'X')
							{
								total--;
							}
							if(grid[i+j][lp] != -1)
							{
								int num = grid[i+j][lp];
								if(u[num] == 1)
								{
									total -= cnt.get(num);
								}
								u[num]--;
							}
						}
						lp++;
					}
					if(rp-lp+1 == k)
					{
						int extra = 0;
						HashSet<Integer> hs = new HashSet<Integer>();
						if(i-1 >= 0)
						{
							for(int ii = 0; ii < k; ii++)
							{
								if(grid[i-1][lp+ii] != -1)
								{
									if(hs.add(grid[i-1][lp+ii]) && u[grid[i-1][lp+ii]] == 0)
									{
										extra += cnt.get(grid[i-1][lp+ii]);
									}
								}
							}
						}
						if(i+k < n)
						{
							for(int ii = 0; ii < k; ii++)
							{
								if(grid[i+k][lp+ii] != -1)
								{
									if(hs.add(grid[i+k][lp+ii]) && u[grid[i+k][lp+ii]] == 0)
									{
										extra += cnt.get(grid[i+k][lp+ii]);
									}
								}
							}
						}
						if(lp-1 >= 0)
						{
							for(int ii = 0; ii < k; ii++)
							{
								if(grid[i+ii][lp-1] != -1)
								{
									if(hs.add(grid[i+ii][lp-1]) && u[grid[i+ii][lp-1]] == 0)
									{
										extra += cnt.get(grid[i+ii][lp-1]);
									}
								}
							}
						}
						if(rp+1 < n)
						{
							for(int ii = 0; ii < k; ii++)
							{
								if(grid[i+ii][rp+1] != -1)
								{
									if(hs.add(grid[i+ii][rp+1]) && u[grid[i+ii][rp+1]] == 0)
									{
										extra += cnt.get(grid[i+ii][rp+1]);
									}
								}
							}
						}
						ret = Math.max(ret, total+extra);
					}
				}
			}
			System.out.println(ret);
		}
		in.close(); out.close();
	}
	int floodfill(int r, int c, int mark)
	{
		int ret = 1;
		for(int i = 0; i < 4; i++)
		{
			int nr = r+dr[i];
			int nc = c+dc[i];
			if(in_bound(nr,nc) && !used[nr][nc] && g[nr].charAt(nc) == '.')
			{
				used[nr][nc] = true;
				grid[nr][nc] = mark;
				ret += floodfill(nr, nc, mark);
			}
		}
		return ret;
	}
	boolean in_bound(int r, int c)
	{
		return 0 <= r && r < n && 0 <= c && c < n;
	}
	class FastScanner
	{
		BufferedReader br;
		StringTokenizer st;
		public FastScanner(InputStream in)
		{
			br = new BufferedReader(new InputStreamReader(in));
			st = new StringTokenizer("");
		}
		public String next() throws IOException
		{
			while(!st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int nextInt() throws IOException
		{
			return Integer.parseInt(next());
		}
		public long nextLong() throws IOException
		{
			return Long.parseLong(next());
		}
		public void close() throws IOException
		{
			br.close();
		}
	}

}

import java.util.*;
import java.io.*;
/*
5 3
.....
.XXX.
.XXX.
.XXX.
.....

 */
public class a
{
	public static void main(String[] args) throws IOException
	{
		new a();
	}
	int n;
	int k;
	String[] g;
	int[][] grid;
	boolean[][] used;
	ArrayList<Integer> cnt;
	int[] dr = new int[]{-1, 1, 0, 0};
	int[] dc = new int[]{0, 0, -1, 1};
	public a() throws IOException
	{
		FastScanner in = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		n = in.nextInt();
		k = in.nextInt();
		if(n == 1)
		{
			System.out.println(1);
		}
		else
		{
			g = new String[n];
			for(int i = 0; i < n; i++) g[i] = in.next();
			grid = new int[n][n];
			for(int[] a : grid) Arrays.fill(a, -1);
			used = new boolean[n][n];
			cnt = new ArrayList<Integer>();
			for(int i = 0; i < n; i++)
			{
				for(int j = 0; j < n; j++)
				{
					if(g[i].charAt(j) == '.' && !used[i][j])
					{
						used[i][j] = true;
						grid[i][j] = cnt.size();
						cnt.add(floodfill(i, j, cnt.size()));
					}
				}
			}

			long ret = 0;
			for(int i = 0; i < cnt.size(); i++) ret = Math.max(ret, cnt.get(i));
			ret = Math.max(ret, k*k);
			for(int i = 0; i <= n-k; i++)
			{
				int lp = 0;
				int rp = -1;
				int total = 0;
				int[] u = new int[cnt.size()];
				while(rp <= n-k)
				{
					rp++;
					for(int j = 0; j < k; j++)
					{
						if(g[i+j].charAt(rp) == 'X')
						{
							total++;
						}
						if(grid[i+j][rp] != -1)
						{
							int num = grid[i+j][rp];
							if(u[num] == 0)
							{
								total += cnt.get(num);
							}
							u[num]++;
						}
					}

					if(rp-lp+1 > k)
					{
						for(int j = 0; j < k; j++)
						{
							if(g[i+j].charAt(lp) == 'X')
							{
								total--;
							}
							if(grid[i+j][lp] != -1)
							{
								int num = grid[i+j][lp];
								if(u[num] == 1)
								{
									total -= cnt.get(num);
								}
								u[num]--;
							}
						}
						lp++;
					}
					if(rp-lp+1 == k)
					{
						int extra = 0;
						HashSet<Integer> hs = new HashSet<Integer>();
						if(i-1 >= 0)
						{
							for(int ii = 0; ii < k; ii++)
							{
								if(grid[i-1][lp+ii] != -1)
								{
									if(hs.add(grid[i-1][lp+ii]) && u[grid[i-1][lp+ii]] == 0)
									{
										extra += cnt.get(grid[i-1][lp+ii]);
									}
								}
							}
						}
						if(i+k < n)
						{
							for(int ii = 0; ii < k; ii++)
							{
								if(grid[i+k][lp+ii] != -1)
								{
									if(hs.add(grid[i+k][lp+ii]) && u[grid[i+k][lp+ii]] == 0)
									{
										extra += cnt.get(grid[i+k][lp+ii]);
									}
								}
							}
						}
						if(lp-1 >= 0)
						{
							for(int ii = 0; ii < k; ii++)
							{
								if(grid[i+ii][lp-1] != -1)
								{
									if(hs.add(grid[i+ii][lp-1]) && u[grid[i+ii][lp-1]] == 0)
									{
										extra += cnt.get(grid[i+ii][lp-1]);
									}
								}
							}
						}
						if(rp+1 < n)
						{
							for(int ii = 0; ii < k; ii++)
							{
								if(grid[i+ii][rp+1] != -1)
								{
									if(hs.add(grid[i+ii][rp+1]) && u[grid[i+ii][rp+1]] == 0)
									{
										extra += cnt.get(grid[i+ii][rp+1]);
									}
								}
							}
						}
						ret = Math.max(ret, total+extra);
					}
				}
			}
			System.out.println(ret);
		}
		in.close(); out.close();
	}
	int floodfill(int r, int c, int mark)
	{
		int ret = 1;
		for(int i = 0; i < 4; i++)
		{
			int nr = r+dr[i];
			int nc = c+dc[i];
			if(in_bound(nr,nc) && !used[nr][nc] && g[nr].charAt(nc) == '.')
			{
				used[nr][nc] = true;
				grid[nr][nc] = mark;
				ret += floodfill(nr, nc, mark);
			}
		}
		return ret;
	}
	boolean in_bound(int r, int c)
	{
		return 0 <= r && r < n && 0 <= c && c < n;
	}
	class FastScanner
	{
		BufferedReader br;
		StringTokenizer st;
		public FastScanner(InputStream in)
		{
			br = new BufferedReader(new InputStreamReader(in));
			st = new StringTokenizer("");
		}
		public String next() throws IOException
		{
			while(!st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int nextInt() throws IOException
		{
			return Integer.parseInt(next());
		}
		public long nextLong() throws IOException
		{
			return Long.parseLong(next());
		}
		public void close() throws IOException
		{
			br.close();
		}
	}

}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.util.Random;
import java.io.IOException;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ilyakor
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        static final int[] dx = new int[]{-1, 1, 0, 0};
        static final int[] dy = new int[]{0, 0, -1, 1};
        int n;
        int k;
        boolean[][] a;
        int[][] sum;
        int[][] sum2;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            n = in.nextInt();
            k = in.nextInt();
//        n = 500;
//        k = 100;
//        Random random = new Random(0xdead);

            TaskC.PersistentDSU dsu = new TaskC.PersistentDSU(n * n + 1);
            int S = n * n;
            dsu.cnt[n * n] = 0;
            a = new boolean[n][n];
            for (int i = 0; i < n; ++i) {
                String s = in.nextToken();
                for (int j = 0; j < n; ++j)
                    a[i][j] = s.charAt(j) == '.';
//            for (int j = 0; j < n; ++j)
//                a[i][j] = random.nextInt(10) != 1;
            }

            sum = new int[n][n];
            for (int i = 0; i < n; ++i) {
                int cur = 0;
                for (int j = 0; j < n; ++j) {
                    cur += a[i][j] ? 0 : 1;
                    if (j - k >= 0) {
                        cur -= a[i][j - k] ? 0 : 1;
                    }
                    if (j - k + 1 >= 0) {
                        sum[i][j - k + 1] = cur;
                    }
                }
            }
            sum2 = new int[n][n];
            for (int i = 0; i < n; ++i) {
                int cur = 0;
                for (int j = 0; j < n; ++j) {
                    cur += sum[j][i];
                    if (j - k >= 0) {
                        cur -= sum[j - k][i];
                    }
                    if (j - k + 1 >= 0) {
                        sum2[j - k + 1][i] = cur;
                    }
                }
            }

            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < n; ++j) {
                    if (!a[i][j]) continue;
                    for (int dir = 0; dir < 4; ++dir) {
                        int x = i + dx[dir];
                        int y = j + dy[dir];
                        if (x >= 0 && x < n && y >= 0 && y < n && a[x][y])
                            dsu.unite(i * n + j, x * n + y);
                    }
                }
            }
            int res = 0;
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < n; ++j) {
                    dsu.root(i * n + j);
                    res = Math.max(res, dsu.cnt[i * n + j]);
                }
            }

            for (int i = 0; i <= n - k; ++i)
                for (int j = 0; j <= n - k; ++j) {
                    dsu.reset();
                    if (j > 0) {
                        for (int x = 0; x < k; ++x) {
                            if (!a[i + x][j - 1]) continue;
                            if (x == 0 || !a[i + x - 1][j - 1])
                                dsu.punite(S, (i + x) * n + j - 1);
                        }
                    }
                    if (j + k < n) {
                        for (int x = 0; x < k; ++x) {
                            if (!a[i + x][j + k]) continue;
                            if (x == 0 || !a[i + x - 1][j + k])
                                dsu.punite(S, (i + x) * n + j + k);
                        }
                    }
                    if (i > 0) {
                        for (int x = 0; x < k; ++x) {
                            if (!a[i - 1][j + x]) continue;
                            if (x == 0 || !a[i - 1][j + x - 1])
                                dsu.punite(S, (i - 1) * n + j + x);
                        }
                    }
                    if (i + k < n) {
                        for (int x = 0; x < k; ++x) {
                            if (!a[i + k][j + x]) continue;
                            if (x == 0 || !a[i + k][j + x - 1])
                                dsu.punite(S, (i + k) * n + j + x);
                        }
                    }
                    int cur = sum2[i][j] + dsu.Cnt[dsu.proot(S)];
                    if (cur > res) res = cur;
                }
            out.printLine(res);
        }

        static class PersistentDSU {
            static Random rnd = new Random();
            int[] p;
            int[] cnt;
            int[] P;
            int[] Cnt;
            int[] u;
            int marker;

            void init() {
                for (int i = 0; i < p.length; i++) {
                    p[i] = i;
                    cnt[i] = 1;
                }
            }

            PersistentDSU(int size) {
                p = new int[size];
                P = new int[size];
                u = new int[size];
                cnt = new int[size];
                Cnt = new int[size];
                marker = 1;
                init();
            }

            void reset() {
                ++marker;
            }

            int root(int x) {
                if (x == p[x])
                    return x;
                return p[x] = root(p[x]);
            }

            void unite(int a, int b) {
                a = root(a);
                b = root(b);
                if (a == b)
                    return;
                if (rnd.nextBoolean()) {
                    p[a] = b;
                    cnt[b] += cnt[a];
                } else {
                    p[b] = a;
                    cnt[a] += cnt[b];
                }
            }

            int proot(int x) {
                if (u[x] != marker) {
                    u[x] = marker;
                    P[x] = p[x];
                    Cnt[x] = cnt[x];
                }
                if (x == P[x]) return x;
                return P[x] = proot(P[x]);
            }

            void punite(int a, int b) {
                a = proot(a);
                b = proot(b);
                if (a == b)
                    return;
                if (rnd.nextBoolean()) {
                    P[a] = b;
                    Cnt[b] += Cnt[a];
                } else {
                    P[b] = a;
                    u[b] = marker;
                    Cnt[a] += Cnt[b];
                }
            }

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void printLine(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buffer = new byte[10000];
        private int cur;
        private int count;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public static boolean isSpace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int read() {
            if (count == -1) {
                throw new InputMismatchException();
            }
            try {
                if (cur >= count) {
                    cur = 0;
                    count = stream.read(buffer);
                    if (count <= 0)
                        return -1;
                }
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            return buffer[cur++];
        }

        public int readSkipSpace() {
            int c;
            do {
                c = read();
            } while (isSpace(c));
            return c;
        }

        public String nextToken() {
            int c = readSkipSpace();
            StringBuilder sb = new StringBuilder();
            while (!isSpace(c)) {
                sb.append((char) c);
                c = read();
            }
            return sb.toString();
        }

        public int nextInt() {
            int sgn = 1;
            int c = readSkipSpace();
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res = res * 10 + c - '0';
                c = read();
            } while (!isSpace(c));
            res *= sgn;
            return res;
        }

    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ilyakor
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        static final int[] dx = new int[]{-1, 1, 0, 0};
        static final int[] dy = new int[]{0, 0, -1, 1};
        int n;
        int k;
        boolean[][] a;
        int[][] sum;
        int[][] sum2;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            n = in.nextInt();
            k = in.nextInt();
//        n = 500;
//        k = 150;
//        Random random = new Random(0xdead);

            TaskC.PersistentDSU dsu = new TaskC.PersistentDSU((n + 2) * (n + 2) + 1, n);
            int S = n * n;
            int N = n + 2;
            a = new boolean[n][n];
            for (int i = 0; i < n; ++i) {
                String s = in.nextToken();
                for (int j = 0; j < n; ++j)
                    a[i][j] = s.charAt(j) == '.';
//            for (int j = 0; j < n; ++j)
//                a[i][j] = random.nextInt(2) == 1;
            }

            sum = new int[n][n];
            for (int i = 0; i < n; ++i) {
                int cur = 0;
                for (int j = 0; j < n; ++j) {
                    cur += a[i][j] ? 0 : 1;
                    if (j - k >= 0) {
                        cur -= a[i][j - k] ? 0 : 1;
                    }
                    if (j - k + 1 >= 0) {
                        sum[i][j - k + 1] = cur;
                    }
                }
            }
            sum2 = new int[n][n];
            for (int i = 0; i < n; ++i) {
                int cur = 0;
                for (int j = 0; j < n; ++j) {
                    cur += sum[j][i];
                    if (j - k >= 0) {
                        cur -= sum[j - k][i];
                    }
                    if (j - k + 1 >= 0) {
                        sum2[j - k + 1][i] = cur;
                    }
                }
            }

            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < n; ++j) {
                    if (!a[i][j]) continue;
                    dsu.cnt[(i + 1) * N + j + 1] = 1;
                }
            }

            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < n; ++j) {
                    if (!a[i][j]) continue;
                    for (int dir = 0; dir < 4; ++dir) {
                        int x = i + dx[dir];
                        int y = j + dy[dir];
                        if (x >= 0 && x < n && y >= 0 && y < n && a[x][y])
                            dsu.unite((i + 1) * N + j + 1, (x + 1) * N + y + 1);
                    }
                }
            }
            int res = 0;
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < n; ++j) {
                    dsu.root(i * N + j);
                    res = Math.max(res, dsu.cnt[i * N + j]);
                }
            }

            int[] del = new int[(n + 2) * (n + 2) + 1];

            for (int i = 0; i <= n - k; ++i) {
                int internal = 0;
                for (int x = 0; x < k; ++x) {
                    for (int y = 0; y < k; ++y) {
                        int t = (i + x + 1) * N + (y + 1);
                        if (dsu.p[t] != t) continue;
                        int mx = dsu.mx[t];
                        int Mx = dsu.Mx[t];
                        int my = dsu.my[t];
                        int My = dsu.My[t];
                        if (mx >= i && Mx <= i + k - 1 && my >= 0 && My <= k - 1)
                            internal += dsu.cnt[t];
                    }
                }
                for (int j = 0; j <= n - k; ++j) {
                    dsu.reset();
                    if (j > 0) for (int x = 0; x < k; ++x) {
                        if (!a[i + x][j - 1]) continue;
                        if (x == 0 || !a[i + x - 1][j - 1])
                            dsu.punite(S, (i + x + 1) * N + j);
                    }
                    if (j + k < n) for (int x = 0; x < k; ++x) {
                        if (!a[i + x][j + k]) continue;
                        if (x == 0 || !a[i + x - 1][j + k])
                            dsu.punite(S, (i + x + 1) * N + j + k + 1);
                    }
                    if (i > 0) for (int x = 0; x < k; ++x) {
                        if (!a[i - 1][j + x]) continue;
                        if (x == 0 || !a[i - 1][j + x - 1])
                            dsu.punite(S, i * N + j + x + 1);
                    }
                    if (i + k < n) for (int x = 0; x < k; ++x) {
                        if (!a[i + k][j + x]) continue;
                        if (x == 0 || !a[i + k][j + x - 1])
                            dsu.punite(S, (i + k + 1) * N + j + x + 1);
                    }
                    int cur = sum2[i][j] + dsu.Cnt[dsu.proot(S)] + internal;
                    if (cur > res) res = cur;

                    int M = dsu.marker;
                    for (int y = 0; y < 2; ++y) {
                        for (int x = 0; x < k; ++x) {
                            if (j + y >= n || !a[i + x][j + y]) continue;
                            int t = (i + x + 1) * N + j + 1 + y;
                            t = dsu.p[t];
                            if (del[t] == M) continue;
                            del[t] = M;
                            int mx = dsu.mx[t];
                            int Mx = dsu.Mx[t];
                            int my = dsu.my[t];
                            int My = dsu.My[t];
                            if (mx >= i && Mx <= i + k - 1 && my >= j && My <= j + k - 1) {
                                if (!(mx >= i && Mx <= i + k - 1 && my >= j + 1 && My <= j + k)) {
                                    internal -= dsu.cnt[t];
                                }
                            }
                        }
                        for (int x = 0; x < k; ++x) {
                            if (j + k - y >= n || j + k - y < 0 || !a[i + x][j + k - y]) continue;
                            int t = (i + x + 1) * N + j + k + 1 - y;
                            t = dsu.p[t];
                            if (del[t] == M) continue;
                            del[t] = M;
                            int mx = dsu.mx[t];
                            int Mx = dsu.Mx[t];
                            int my = dsu.my[t];
                            int My = dsu.My[t];
                            if (!(mx >= i && Mx <= i + k - 1 && my >= j && My <= j + k - 1)) {
                                if ((mx >= i && Mx <= i + k - 1 && my >= j + 1 && My <= j + k)) {
                                    internal += dsu.cnt[t];
                                }
                            }
                        }
                    }
                }
            }
            out.printLine(res);
        }

        static class PersistentDSU {
            int[] p;
            int[] cnt;
            int[] Mx;
            int[] mx;
            int[] My;
            int[] my;
            int[] P;
            int[] Cnt;
            int[] u;
            int marker;
            int n;

            void init() {
                for (int i = 0; i < p.length; i++) {
                    p[i] = i;
                    cnt[i] = 0;
                    mx[i] = i / (n + 2) - 1;
                    my[i] = i % (n + 2) - 1;
                    Mx[i] = i / (n + 2) - 1;
                    My[i] = i % (n + 2) - 1;
                }
            }

            PersistentDSU(int size, int n) {
                this.n = n;
                p = new int[size];
                P = new int[size];
                mx = new int[size];
                Mx = new int[size];
                my = new int[size];
                My = new int[size];
                u = new int[size];
                cnt = new int[size];
                Cnt = new int[size];
                marker = 1;
                init();
            }

            void reset() {
                ++marker;
            }

            int root(int x) {
                if (x == p[x])
                    return x;
                return p[x] = root(p[x]);
            }

            void unite(int a, int b) {
                a = root(a);
                b = root(b);
                if (a == b)
                    return;
                //if (rnd.nextBoolean()) {
                if ((((a * 57 + b * 43) ^ (a * b + 12)) >> 3) % 2 == 0) {
                    p[a] = b;
                    cnt[b] += cnt[a];
                    if (mx[b] > mx[a]) mx[b] = mx[a];
                    if (my[b] > my[a]) my[b] = my[a];
                    if (Mx[b] < Mx[a]) Mx[b] = Mx[a];
                    if (My[b] < My[a]) My[b] = My[a];
                } else {
                    p[b] = a;
                    cnt[a] += cnt[b];
                    if (mx[a] > mx[b]) mx[a] = mx[b];
                    if (my[a] > my[b]) my[a] = my[b];
                    if (Mx[a] < Mx[b]) Mx[a] = Mx[b];
                    if (My[a] < My[b]) My[a] = My[b];
                }
            }

            int proot(int x) {
                if (u[x] != marker) {
                    u[x] = marker;
                    P[x] = p[x];
                    Cnt[x] = cnt[x];
                }
                if (x == P[x]) return x;
                return P[x] = proot(P[x]);
            }

            void punite(int a, int b) {
                a = proot(a);
                b = proot(b);
                if (a == b)
                    return;
                //if (rnd.nextBoolean()) {
                if ((((a * 57 + b * 43) ^ (a * b + 12)) >> 3) % 2 == 0) {
                    P[a] = b;
                    Cnt[b] += Cnt[a];
                } else {
                    P[b] = a;
                    u[b] = marker;
                    Cnt[a] += Cnt[b];
                }
            }

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void printLine(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buffer = new byte[10000];
        private int cur;
        private int count;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public static boolean isSpace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int read() {
            if (count == -1) {
                throw new InputMismatchException();
            }
            try {
                if (cur >= count) {
                    cur = 0;
                    count = stream.read(buffer);
                    if (count <= 0)
                        return -1;
                }
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            return buffer[cur++];
        }

        public int readSkipSpace() {
            int c;
            do {
                c = read();
            } while (isSpace(c));
            return c;
        }

        public String nextToken() {
            int c = readSkipSpace();
            StringBuilder sb = new StringBuilder();
            while (!isSpace(c)) {
                sb.append((char) c);
                c = read();
            }
            return sb.toString();
        }

        public int nextInt() {
            int sgn = 1;
            int c = readSkipSpace();
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res = res * 10 + c - '0';
                c = read();
            } while (!isSpace(c));
            res *= sgn;
            return res;
        }

    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ilyakor
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        static final int[] dx = new int[]{-1, 1, 0, 0};
        static final int[] dy = new int[]{0, 0, -1, 1};
        int n;
        int k;
        boolean[][] a;
        int[][] sum;
        int[][] sum2;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            n = in.nextInt();
            k = in.nextInt();
//        n = 500;
//        k = 150;
//        Random random = new Random(0xdead);

            TaskC.PersistentDSU dsu = new TaskC.PersistentDSU((n + 2) * (n + 2) + 1, n);
            int S = n * n;
            a = new boolean[n][n];
            for (int i = 0; i < n; ++i) {
                String s = in.nextToken();
                for (int j = 0; j < n; ++j)
                    a[i][j] = s.charAt(j) == '.';
//            for (int j = 0; j < n; ++j)
//                a[i][j] = random.nextInt(2) == 1;
            }

            sum = new int[n][n];
            for (int i = 0; i < n; ++i) {
                int cur = 0;
                for (int j = 0; j < n; ++j) {
                    cur += a[i][j] ? 0 : 1;
                    if (j - k >= 0) {
                        cur -= a[i][j - k] ? 0 : 1;
                    }
                    if (j - k + 1 >= 0) {
                        sum[i][j - k + 1] = cur;
                    }
                }
            }
            sum2 = new int[n][n];
            for (int i = 0; i < n; ++i) {
                int cur = 0;
                for (int j = 0; j < n; ++j) {
                    cur += sum[j][i];
                    if (j - k >= 0) {
                        cur -= sum[j - k][i];
                    }
                    if (j - k + 1 >= 0) {
                        sum2[j - k + 1][i] = cur;
                    }
                }
            }

            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < n; ++j) {
                    if (!a[i][j]) continue;
                    dsu.cnt[(i + 1) * n + j + 1] = 1;
                }
            }

            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < n; ++j) {
                    if (!a[i][j]) continue;
                    for (int dir = 0; dir < 4; ++dir) {
                        int x = i + dx[dir];
                        int y = j + dy[dir];
                        if (x >= 0 && x < n && y >= 0 && y < n && a[x][y])
                            dsu.unite((i + 1) * n + j + 1, (x + 1) * n + y + 1);
                    }
                }
            }
            int res = 0;
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < n; ++j) {
                    dsu.root(i * n + j);
                    res = Math.max(res, dsu.cnt[i * n + j]);
                }
            }

            int[] del = new int[(n + 2) * (n + 2) + 1];

            for (int i = 0; i <= n - k; ++i) {
                int internal = 0;
                for (int x = 0; x < k; ++x) {
                    for (int y = 0; y < k; ++y) {
                        int t = (i + x + 1) * n + (y + 1);
                        if (dsu.p[t] != t) continue;
                        int mx = dsu.mx[t];
                        int Mx = dsu.Mx[t];
                        int my = dsu.my[t];
                        int My = dsu.My[t];
                        if (mx >= i && Mx <= i + k - 1 && my >= 0 && My <= k - 1)
                            internal += dsu.cnt[t];
                    }
                }
                for (int j = 0; j <= n - k; ++j) {
                    dsu.reset();
                    if (j > 0) for (int x = 0; x < k; ++x) {
                        if (!a[i + x][j - 1]) continue;
                        if (x == 0 || !a[i + x - 1][j - 1])
                            dsu.punite(S, (i + x + 1) * n + j);
                    }
                    if (j + k < n) for (int x = 0; x < k; ++x) {
                        if (!a[i + x][j + k]) continue;
                        if (x == 0 || !a[i + x - 1][j + k])
                            dsu.punite(S, (i + x + 1) * n + j + k + 1);
                    }
                    if (i > 0) for (int x = 0; x < k; ++x) {
                        if (!a[i - 1][j + x]) continue;
                        if (x == 0 || !a[i - 1][j + x - 1])
                            dsu.punite(S, i * n + j + x + 1);
                    }
                    if (i + k < n) for (int x = 0; x < k; ++x) {
                        if (!a[i + k][j + x]) continue;
                        if (x == 0 || !a[i + k][j + x - 1])
                            dsu.punite(S, (i + k + 1) * n + j + x + 1);
                    }
                    int cur = sum2[i][j] + dsu.Cnt[dsu.proot(S)] + internal;
                    if (cur > res) res = cur;

                    int M = dsu.marker;
                    for (int y = 0; y < 2; ++y) {
                        for (int x = 0; x < k; ++x) {
                            if (j + y >= n || !a[i + x][j + y]) continue;
                            int t = (i + x + 1) * n + j + 1 + y;
                            t = dsu.p[t];
                            if (del[t] == M) continue;
                            del[t] = M;
                            int mx = dsu.mx[t];
                            int Mx = dsu.Mx[t];
                            int my = dsu.my[t];
                            int My = dsu.My[t];
                            if (mx >= i && Mx <= i + k - 1 && my >= j && My <= j + k - 1) {
                                if (!(mx >= i && Mx <= i + k - 1 && my >= j + 1 && My <= j + k)) {
                                    internal -= dsu.cnt[t];
                                }
                            }
                        }
                        for (int x = 0; x < k; ++x) {
                            if (j + k - y >= n || j + k - y < 0 || !a[i + x][j + k - y]) continue;
                            int t = (i + x + 1) * n + j + k + 1 - y;
                            t = dsu.p[t];
                            if (del[t] == M) continue;
                            del[t] = M;
                            int mx = dsu.mx[t];
                            int Mx = dsu.Mx[t];
                            int my = dsu.my[t];
                            int My = dsu.My[t];
                            if (!(mx >= i && Mx <= i + k - 1 && my >= j && My <= j + k - 1)) {
                                if ((mx >= i && Mx <= i + k - 1 && my >= j + 1 && My <= j + k)) {
                                    internal += dsu.cnt[t];
                                }
                            }
                        }
                    }
                }
            }
            out.printLine(res);
        }

        static class PersistentDSU {
            int[] p;
            int[] cnt;
            int[] Mx;
            int[] mx;
            int[] My;
            int[] my;
            int[] P;
            int[] Cnt;
            int[] u;
            int marker;
            int n;

            void init() {
                for (int i = 0; i < p.length; i++) {
                    p[i] = i;
                    cnt[i] = 0;
                    mx[i] = i / n - 1;
                    my[i] = i % n - 1;
                    Mx[i] = i / n - 1;
                    My[i] = i % n - 1;
                }
            }

            PersistentDSU(int size, int n) {
                this.n = n;
                p = new int[size];
                P = new int[size];
                mx = new int[size];
                Mx = new int[size];
                my = new int[size];
                My = new int[size];
                u = new int[size];
                cnt = new int[size];
                Cnt = new int[size];
                marker = 1;
                init();
            }

            void reset() {
                ++marker;
            }

            int root(int x) {
                if (x == p[x])
                    return x;
                return p[x] = root(p[x]);
            }

            void unite(int a, int b) {
                a = root(a);
                b = root(b);
                if (a == b)
                    return;
                //if (rnd.nextBoolean()) {
                if ((((a * 57 + b * 43) ^ (a * b + 12)) >> 3) % 2 == 0) {
                    p[a] = b;
                    cnt[b] += cnt[a];
                    if (mx[b] > mx[a]) mx[b] = mx[a];
                    if (my[b] > my[a]) my[b] = my[a];
                    if (Mx[b] < Mx[a]) Mx[b] = Mx[a];
                    if (My[b] < My[a]) My[b] = My[a];
                } else {
                    p[b] = a;
                    cnt[a] += cnt[b];
                    if (mx[a] > mx[b]) mx[a] = mx[b];
                    if (my[a] > my[b]) my[a] = my[b];
                    if (Mx[a] < Mx[b]) Mx[a] = Mx[b];
                    if (My[a] < My[b]) My[a] = My[b];
                }
            }

            int proot(int x) {
                if (u[x] != marker) {
                    u[x] = marker;
                    P[x] = p[x];
                    Cnt[x] = cnt[x];
                }
                if (x == P[x]) return x;
                return P[x] = proot(P[x]);
            }

            void punite(int a, int b) {
                a = proot(a);
                b = proot(b);
                if (a == b)
                    return;
                //if (rnd.nextBoolean()) {
                if ((((a * 57 + b * 43) ^ (a * b + 12)) >> 3) % 2 == 0) {
                    P[a] = b;
                    Cnt[b] += Cnt[a];
                } else {
                    P[b] = a;
                    u[b] = marker;
                    Cnt[a] += Cnt[b];
                }
            }

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void printLine(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buffer = new byte[10000];
        private int cur;
        private int count;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public static boolean isSpace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int read() {
            if (count == -1) {
                throw new InputMismatchException();
            }
            try {
                if (cur >= count) {
                    cur = 0;
                    count = stream.read(buffer);
                    if (count <= 0)
                        return -1;
                }
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            return buffer[cur++];
        }

        public int readSkipSpace() {
            int c;
            do {
                c = read();
            } while (isSpace(c));
            return c;
        }

        public String nextToken() {
            int c = readSkipSpace();
            StringBuilder sb = new StringBuilder();
            while (!isSpace(c)) {
                sb.append((char) c);
                c = read();
            }
            return sb.toString();
        }

        public int nextInt() {
            int sgn = 1;
            int c = readSkipSpace();
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res = res * 10 + c - '0';
                c = read();
            } while (!isSpace(c));
            res *= sgn;
            return res;
        }

    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 29);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            CBearAndSquareGrid solver = new CBearAndSquareGrid();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class CBearAndSquareGrid {
        boolean[][] visited;
        int ans;
        int sum;
        int[] conn;
        int x;
        int y;
        int k;
        int n;
        int[][] mat;
        int[][] cc;
        int[] size;
        int[][] ps;

        public void solve(int testNumber, FastInput in, FastOutput out) {
            n = in.readInt();
            k = in.readInt();
            mat = new int[n + 2][n + 2];
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= n; j++) {
                    mat[i][j] = in.readChar() == '.' ? 0 : 1;
                }
            }
            ps = new int[n + 2][n + 2];
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= n; j++) {
                    ps[i][j] = mat[i][j];
                    ps[i][j] += ps[i][j - 1];
                }
                for (int j = 1; j <= n; j++) {
                    ps[i][j] += ps[i - 1][j];
                }
            }

            cc = new int[n + 2][n + 2];
            size = new int[n * n + 1];
            SequenceUtils.deepFill(cc, 0);
            int order = 1;
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= n; j++) {
                    if (mat[i][j] == 0 && cc[i][j] == 0) {
                        size[order] = dfs(i, j, order);
                        order++;
                    }
                }
            }
            conn = new int[order];
            visited = new boolean[n + 2][n + 2];

            for (int i = 0; i <= k + 1; i++) {
                for (int j = 0; j <= k + 1; j++) {
                    add(i, j, 1);
                }
            }
            add(0, 0, -1);
            add(1 + k, 0, -1);
            add(0, 1 + k, -1);
            add(1 + k, 1 + k, -1);
            x = 1;
            y = 1;
            dfsForMove();

            out.println(ans);
        }

        public boolean check2(int i, int j) {
            return i >= 1 && i + k - 1 <= n && j >= 1 && j + k - 1 <= n && !visited[i][j];
        }

        public void dfsForMove() {
            visited[x][y] = true;
            update();
            if (check2(x + 1, y)) {
                moveDown(1);
                dfsForMove();
                return;
            }
            if (check2(x, y + 1)) {
                moveRight(1);
                dfsForMove();
                return;
            }
            if (check2(x - 1, y)) {
                moveDown(-1);
                dfsForMove();
                return;
            }
            if (check2(x, y - 1)) {
                moveRight(-1);
                dfsForMove();
                return;
            }
        }

        public void update() {
            int cand = sum + region(x, x + k - 1, y, y + k - 1);
            ans = Math.max(ans, cand);
        }

        public void moveDown(int sign) {
            for (int i = 0; i < k; i++) {
                add(x - 1, y + i, -sign);
            }
            add(x, y - 1, -sign);
            add(x, y + k, -sign);

            x += sign;
            for (int i = 0; i < k; i++) {
                add(x + k, y + i, sign);
            }
            add(x + k - 1, y - 1, sign);
            add(x + k - 1, y + k, sign);
        }

        public void moveRight(int sign) {
            for (int i = 0; i < k; i++) {
                add(x + i, y - 1, -sign);
            }
            add(x - 1, y, -sign);
            add(x + k, y, -sign);

            y += sign;
            for (int i = 0; i < k; i++) {
                add(x + i, y + k, sign);
            }
            add(x - 1, y + k - 1, sign);
            add(x + k, y + k - 1, sign);
        }

        public boolean check(int i, int j) {
            return !(i < 1 || j < 1 || i > n || j > n);
        }

        public void add(int i, int j, int x) {
            int id = cc[i][j];
            if (conn[id] == 0) {
                sum += size[id];
            }
            conn[id] += x;
            if (conn[id] == 0) {
                sum -= size[id];
            }
        }

        public int region(int b, int t, int l, int r) {
            int ans = ps[t][r];
            if (l > 0) {
                ans -= ps[t][l - 1];
            }
            if (b > 0) {
                ans -= ps[b - 1][r];
            }
            if (l > 0 && b > 0) {
                ans += ps[b - 1][l - 1];
            }
            return ans;
        }

        public int dfs(int i, int j, int id) {
            if (!check(i, j) || mat[i][j] == 1 || cc[i][j] != 0) {
                return 0;
            }
            cc[i][j] = id;
            return dfs(i + 1, j, id) + dfs(i - 1, j, id) + dfs(i, j - 1, id) + dfs(i, j + 1, id) + 1;
        }

    }

    static class FastOutput implements AutoCloseable, Closeable, Appendable {
        private StringBuilder cache = new StringBuilder(10 << 20);
        private final Writer os;

        public FastOutput append(CharSequence csq) {
            cache.append(csq);
            return this;
        }

        public FastOutput append(CharSequence csq, int start, int end) {
            cache.append(csq, start, end);
            return this;
        }

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput append(char c) {
            cache.append(c);
            return this;
        }

        public FastOutput append(int c) {
            cache.append(c);
            return this;
        }

        public FastOutput println(int c) {
            return append(c).println();
        }

        public FastOutput println() {
            cache.append(System.lineSeparator());
            return this;
        }

        public FastOutput flush() {
            try {
                os.append(cache);
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }

    static class SequenceUtils {
        public static void deepFill(Object array, int val) {
            if (!array.getClass().isArray()) {
                throw new IllegalArgumentException();
            }
            if (array instanceof int[]) {
                int[] intArray = (int[]) array;
                Arrays.fill(intArray, val);
            } else {
                Object[] objArray = (Object[]) array;
                for (Object obj : objArray) {
                    deepFill(obj, val);
                }
            }
        }

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

        public char readChar() {
            skipBlank();
            char c = (char) next;
            next = read();
            return c;
        }

    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 29);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            CBearAndSquareGrid solver = new CBearAndSquareGrid();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class CBearAndSquareGrid {
        boolean[][] visited;
        int ans;
        int sum;
        int[] conn;
        int x;
        int y;
        int k;
        int n;
        int[][] mat;
        int[][] cc;
        int[] size;
        int[][] ps;

        public void solve(int testNumber, FastInput in, FastOutput out) {
            n = in.readInt();
            k = in.readInt();
            mat = new int[n + 2][n + 2];
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= n; j++) {
                    mat[i][j] = in.readChar() == '.' ? 0 : 1;
                }
            }
            ps = new int[n + 2][n + 2];
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= n; j++) {
                    ps[i][j] = mat[i][j];
                    ps[i][j] += ps[i][j - 1];
                }
                for (int j = 1; j <= n; j++) {
                    ps[i][j] += ps[i - 1][j];
                }
            }

            cc = new int[n + 2][n + 2];
            size = new int[n * n + 1];
            SequenceUtils.deepFill(cc, 0);
            int order = 1;
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= n; j++) {
                    if (mat[i][j] == 0 && cc[i][j] == 0) {
                        size[order] = dfs(i, j, order);
                        order++;
                    }
                }
            }
            conn = new int[order];
            visited = new boolean[n + 2][n + 2];
            x = 1;
            y = 1;
            dfsForMove();

            out.println(ans);
        }

        public boolean check2(int i, int j) {
            return i >= 1 && i + k - 1 <= n && j >= 1 && j + k - 1 <= n && !visited[i][j];
        }

        public void dfsForMove() {
            visited[x][y] = true;
            update();
            if (check2(x + 1, y)) {
                moveDown(1);
                dfsForMove();
                return;
            }
            if (check2(x, y + 1)) {
                moveRight(1);
                dfsForMove();
                return;
            }
            if (check2(x - 1, y)) {
                moveDown(-1);
                dfsForMove();
                return;
            }
            if (check2(x, y - 1)) {
                moveRight(-1);
                dfsForMove();
                return;
            }
        }

        public void update() {
            int cand = sum + region(x, x + k - 1, y, y + k - 1);
            ans = Math.max(ans, cand);
        }

        public void moveDown(int sign) {
            for (int i = 0; i < k; i++) {
                add(x - 1, y + i, -sign);
            }
            add(x, y - 1, -sign);
            add(x, y + k, -sign);

            x += sign;
            for (int i = 0; i < k; i++) {
                add(x + k, y + i, sign);
            }
            add(x + k - 1, y - 1, sign);
            add(x + k - 1, y + k, sign);
        }

        public void moveRight(int sign) {
            for (int i = 0; i < k; i++) {
                add(x + i, y - 1, -sign);
            }
            add(x - 1, y, -sign);
            add(x + k, y, -sign);

            y += sign;
            for (int i = 0; i < k; i++) {
                add(x + i, y + k, sign);
            }
            add(x - 1, y + k - 1, sign);
            add(x + k, y + k - 1, sign);
        }

        public boolean check(int i, int j) {
            return !(i < 1 || j < 1 || i > n || j > n);
        }

        public void add(int i, int j, int x) {
            int id = cc[i][j];
            if (conn[id] == 0) {
                sum += size[id];
            }
            conn[id] += x;
            if (conn[id] == 0) {
                sum -= size[id];
            }
        }

        public int region(int b, int t, int l, int r) {
            int ans = ps[t][r];
            if (l > 0) {
                ans -= ps[t][l - 1];
            }
            if (b > 0) {
                ans -= ps[b - 1][r];
            }
            if (l > 0 && b > 0) {
                ans += ps[b - 1][l - 1];
            }
            return ans;
        }

        public int dfs(int i, int j, int id) {
            if (!check(i, j) || mat[i][j] == 1 || cc[i][j] != 0) {
                return 0;
            }
            cc[i][j] = id;
            return dfs(i + 1, j, id) + dfs(i - 1, j, id) + dfs(i, j - 1, id) + dfs(i, j + 1, id) + 1;
        }

    }

    static class FastOutput implements AutoCloseable, Closeable, Appendable {
        private StringBuilder cache = new StringBuilder(10 << 20);
        private final Writer os;

        public FastOutput append(CharSequence csq) {
            cache.append(csq);
            return this;
        }

        public FastOutput append(CharSequence csq, int start, int end) {
            cache.append(csq, start, end);
            return this;
        }

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput append(char c) {
            cache.append(c);
            return this;
        }

        public FastOutput append(int c) {
            cache.append(c);
            return this;
        }

        public FastOutput println(int c) {
            return append(c).println();
        }

        public FastOutput println() {
            cache.append(System.lineSeparator());
            return this;
        }

        public FastOutput flush() {
            try {
                os.append(cache);
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }

    static class SequenceUtils {
        public static void deepFill(Object array, int val) {
            if (!array.getClass().isArray()) {
                throw new IllegalArgumentException();
            }
            if (array instanceof int[]) {
                int[] intArray = (int[]) array;
                Arrays.fill(intArray, val);
            } else {
                Object[] objArray = (Object[]) array;
                for (Object obj : objArray) {
                    deepFill(obj, val);
                }
            }
        }

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

        public char readChar() {
            skipBlank();
            char c = (char) next;
            next = read();
            return c;
        }

    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BearAndSquareGrid solver = new BearAndSquareGrid();
        solver.solve(1, in, out);
        out.close();
    }

    static class BearAndSquareGrid {
        ArrayList<Integer>[][] connected = new ArrayList[502][502];
        int[] sz = new int[500 * 500 + 5];
        int[] active = new int[500 * 500 + 5];
        int res = 0;
        int K;
        int N;
        boolean[][] blocked;
        boolean[][] visited = new boolean[502][502];
        int[][] component = new int[502][502];
        int count = 1;
        int[] moveR = new int[]{-1, 0, 1, 0};
        int[] moveC = new int[]{0, 1, 0, -1};

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            N = in.nextInt();
            K = in.nextInt();
            blocked = new boolean[N + 2][N + 2];
            for (int i = 1; i <= N; i++) {
                char[] row = in.next().toCharArray();
                for (int j = 1; j <= N; j++) {
                    blocked[i][j] = (row[j - 1] == 'X');
                }
            }
            for (int i = 0; i <= N + 1; i++) {
                for (int j = 0; j <= N + 1; j++) {
                    if (i == 0 || j == 0 || j == N + 1 || i == N + 1) {
                        blocked[i][j] = true;
                    }
                }
            }
            for (int i = 1; i <= N; i++) {
                for (int j = 1; j <= N; j++) {
                    if (!visited[i][j] && !blocked[i][j]) {
                        floodFill(i, j);
                        count++;
                    }
                }
            }
            for (int i = 1; i <= N; i++) {
                for (int j = 1; j <= N; j++) {
                    connected[i][j] = new ArrayList<>();
                    if (!blocked[i][j]) {
                        connected[i][j].add(component[i][j]);
                    } else {
                        for (int m = 0; m < 4; m++) {
                            if (!blocked[i + moveR[m]][j + moveC[m]]) {
                                connected[i][j].add(component[i + moveR[m]][j + moveC[m]]);
                            }
                        }
                    }
                }
            }
            for (int i = 1; i <= K; i++) {
                rowK(1, i, false);
            }
            int ans = res;
            int curR = K;
            int curC = K;
            while (curR <= N) {
                if (curC == K) {
                    while (curC + 1 <= N) {
                        colK(curR - K + 1, curC - K + 1, true);
                        curC++;
                        colK(curR - K + 1, curC, false);
                        ans = Math.max(ans, res);
                    }
                } else if (curC == N) {
                    while (curC - 1 >= K) {
                        colK(curR - K + 1, curC, true);
                        curC--;
                        colK(curR - K + 1, curC - K + 1, false);
                        ans = Math.max(ans, res);
                    }
                }
                if (curR + 1 <= N) {
                    rowK(curC - K + 1, curR - K + 1, true);
                    curR++;
                    rowK(curC - K + 1, curR, false);
                    ans = Math.max(ans, res);
                } else {
                    break;
                }
            }
            out.println(ans);
        }

        void colK(int startRow, int col, boolean rem) {
            //add kValues starting from [startRow] at the col'th column
            for (int i = startRow; i <= startRow + K - 1; i++) {
                if (blocked[i][col]) {
                    if (rem) {
                        res--;
                    } else {
                        res++;
                    }
                }
                for (int c : connected[startRow][col]) {
                    if (rem) {
                        remove(c);
                    } else {
                        add(c);
                    }
                }
            }
        }

        void rowK(int startCol, int row, boolean rem) {
            for (int j = startCol; j <= startCol + K - 1; j++) {
                if (blocked[row][j]) {
                    if (rem) {
                        res--;
                    } else {
                        res++;
                    }
                }
                for (int c : connected[row][j]) {
                    if (rem) {
                        remove(c);
                    } else {
                        add(c);
                    }
                }
            }
        }

        void add(int comp) {
            active[comp]++;
            if (active[comp] == 1) {
                res += sz[comp];
            }
        }

        void remove(int comp) {
            active[comp]--;
            if (active[comp] == 0) {
                res -= sz[comp];
            }
        }

        void floodFill(int r, int c) {
            visited[r][c] = true;
            component[r][c] = count;
            sz[count]++;
            for (int i = 0; i < 4; i++) {
                if (!visited[r + moveR[i]][c + moveC[i]] && !blocked[r + moveR[i]][c + moveC[i]]) {
                    floodFill(r + moveR[i], c + moveC[i]);
                }
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class ProblemC2 {
    private static final Integer ONE = 1;
    BufferedReader rd;
    int[] inside;
    int[] size;
    int n, k;
    int res;
    char[][] c;
    int[][] idOf;

    ProblemC2() throws IOException {
        rd = new BufferedReader(new InputStreamReader(System.in));
        compute();
    }

    private void compute() throws IOException {
        int[] a = intarr();
        n = a[0];
        k = a[1];
        if(k == n) {
            res = n*n;
        } else {
            c = new char[n][];
            for (int i = 0; i < n; i++) {
                c[i] = rd.readLine().toCharArray();
            }
            idOf = new int[n][n];
            size = new int[250000];
            boolean[][] vis = new boolean[n][n];
            int[] cx = new int[]{-1, 1, 0, 0};
            int[] cy = new int[]{0, 0, -1, 1};
            Queue<Pair> q = new ArrayDeque<>();
            int maxId = 1;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if (!vis[i][j] && c[i][j] == '.') {
                        Set<Pair> pts = new HashSet<>();
                        q.add(new Pair(i, j));
                        while (!q.isEmpty()) {
                            Pair p = q.poll();
                            pts.add(p);
                            for (int m = 0; m < 4; m++) {
                                int g = p.v[0] + cx[m];
                                int h = p.v[1] + cy[m];
                                if (g >= 0 && g < n && h >= 0 && h < n) {
                                    if (!vis[g][h] && c[g][h] == '.') {
                                        vis[g][h] = true;
                                        q.add(new Pair(g, h));
                                    }
                                }
                            }
                        }
                        size[maxId] = pts.size();
                        for (Pair p : pts) {
                            idOf[p.v[0]][p.v[1]] = maxId;
                        }
                        maxId++;
                    }
                }
            }
            inside = new int[maxId];
            for (int i = 0; i < k; i++) {
                for (int j = 0; j < k; j++) {
                    if (c[i][j] == '.') {
                        inside[idOf[i][j]]++;
                    }
                }
            }

            computeSize(0,0);

            int z = n - k;
            for (int i = 0; i <= z; i++) {
                for (int j = 0; j < z; j++) {
                    if (i % 2 == 0) {
                        updateInside(i, j + k, 1, 0, 1);
                        updateInside(i, j, 1, 0, -1);
                        computeSize(i,j+1);
                    } else {
                        updateInside(i, n - j - k - 1, 1, 0, 1);
                        updateInside(i, n - j - 1, 1, 0, -1);
                        computeSize(i,z-j-1);
                    }
                }
                if (i < z) {
                    if (i % 2 == 0) {
                        updateInside(i, z, 0, 1, -1);
                        updateInside(i + k, z, 0, 1, 1);
                        computeSize(i+1,z);
                    } else {
                        updateInside(i, 0, 0, 1, -1);
                        updateInside(i + k, z, 0, 1, 1);
                        computeSize(i+1,0);
                    }
                }
            }
        }
        out(res);
    }

    private void inc(Map<Integer, Integer> m, Integer key) {
        m.put(key, m.getOrDefault(key, 0) + 1);
    }

    private void dec(Map<Integer, Integer> m, Integer key) {
        Integer cur = m.get(key);
        if(cur != null) {
            if (cur.equals(ONE)) {
                m.remove(key);
            } else {
                m.put(key, cur - 1);
            }
        }
    }

    private void updateTouch(Map<Integer, Integer> touch, int x, int y, int zx, int zy, int count, boolean add) {
        for(int j=0;j<count;j++) {
            if(x >= 0 && x < n && y >= 0 && y < n) {
                if(c[x][y] == '.') {
                    int id = idOf[x][y];
                    if(add) {
                        inc(touch, id);
                    } else {
                        dec(touch, id);
                    }
                }
            } else {
                return;
            }
            x += zx;
            y += zy;
        }
    }

    private void updateInside(int x, int y, int zx, int zy, int diff) {
        for(int j=0;j<k;j++) {
            if (c[x][y] == '.') {
                inside[idOf[x][y]] += diff;
            }
            x += zx;
            y += zy;
        }
    }

    private void computeSize(int i, int j) {
        Map<Integer, Integer> touch = new HashMap<>();
        updateTouch(touch, i-1, j, 0, 1, k, true);
        updateTouch(touch, i, j-1, 1, 0, k, true);
        updateTouch(touch, i, j+k, 1, 0, k, true);
        updateTouch(touch, i+k, j, 0, 1, k, true);
        int max = k*k;
        for(Map.Entry<Integer, Integer> t: touch.entrySet()) {
            int key = t.getKey();
            max += size[key] - inside[key];
        }
        res = Math.max(res, max);
    }

    class Pair {
        final int[] v;

        Pair(int a, int b) {
            v = new int[] { a, b };
        }

        Pair(int[] x) {
            v = x;
        }

        public boolean equals(Object o) {
            if (this == o) return true;
            if (o instanceof Pair) {
                return Arrays.equals(v, ((Pair) o).v);
            }
            return false;
        }

        public int hashCode() {
            return v != null ? Arrays.hashCode(v) : 0;
        }

        public String toString() {
            return Arrays.toString(v);
        }
    }

    private int[] intarr() throws IOException {
        return intarr(rd.readLine());
    }

    private int[] intarr(String s) {
        String[] q = split(s);
        int n = q.length;
        int[] a = new int[n];
        for(int i=0;i<n;i++) {
            a[i] = Integer.parseInt(q[i]);
        }
        return a;
    }

    public String[] split(String s) {
        if(s == null) {
            return new String[0];
        }
        int n = s.length();
        int start = -1;
        int end = 0;
        int sp = 0;
        boolean lastWhitespace = true;
        for(int i=0;i<n;i++) {
            char c = s.charAt(i);
            if(isWhitespace(c)) {
                lastWhitespace = true;
            } else {
                if(lastWhitespace) {
                    sp++;
                }
                if(start == -1) {
                    start = i;
                }
                end = i;
                lastWhitespace = false;
            }
        }
        if(start == -1) {
            return new String[0];
        }
        String[] res = new String[sp];
        int last = start;
        int x = 0;
        lastWhitespace = true;
        for(int i=start;i<=end;i++) {
            char c = s.charAt(i);
            boolean w = isWhitespace(c);
            if(w && !lastWhitespace) {
                res[x++] = s.substring(last,i);
            } else if(!w && lastWhitespace) {
                last = i;
            }
            lastWhitespace = w;
        }
        res[x] = s.substring(last,end+1);
        return res;
    }

    private boolean isWhitespace(char c) {
        return c==' ' || c=='\t';
    }

    private static void out(Object x) {
        System.out.println(x);
    }

    public static void main(String[] args) throws IOException {
        new ProblemC2();
    }
}

import sun.awt.image.ImageWatched;

import java.io.*;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.LinkedList;

public class Cf0806E {
    private static InputReader in = new InputReader(System.in);
    private static OutputWriter out = new OutputWriter(System.out);
    private static int n,k;
    private static int[][] grid;
    private static int component;
    private static int[][] cc;

    private static void dfs(int x, int y){
        if((x==-1||x==n||y==-1||y==n)||(cc[x][y]!=0)||(grid[x][y]==0)){
            return;
        }
        cc[x][y] = component;
        dfs(x+1,y);
        dfs(x-1,y);
        dfs(x,y+1);
        dfs(x,y-1);
    }

    private static void solve() throws Exception{
        n = in.readInt();
        k = in.readInt();
        grid = new int[n][n];
        cc = new int[n][n];
        for(int i=0; i<n; ++i){
            String s = in.readString();
            for(int j=0; j<n; ++j){
                if(s.charAt(j)=='.'){
                    grid[i][j] = 1;
                }
            }
        }
        for(int i=0; i<n; ++i){
            for(int j=0; j<n; ++j){
                if((cc[i][j]!=0)||(grid[i][j]==0)){
                    continue;
                }
                component++;
                dfs(i,j);
            }
        }
        int[] totalCount = new int[component+1];
        for(int i=0; i<n; ++i){
            for(int j=0; j<n;++j){
                totalCount[cc[i][j]]++;
            }
        }

        int answer = 0;
        for(int i=0; i<=n-k;++i){
            int[] count = new int[component+1];
            for(int z=i; z<i+k; ++z) {
                for (int j = 0; j < k - 1; ++j) {
                    count[cc[z][j]]++;
                }
            }
            for(int j=k-1; j<n; ++j) {
                for(int z=i; z<i+k; ++z) {
                    count[cc[z][j]]++;
                }

                HashSet<Integer> markSet = new HashSet<>();
                LinkedList<Integer> ccList = new LinkedList<>();

                if(j!=n-1){
                    for(int z=i; z<i+k; ++z){
                        if(cc[z][j+1]==0){
                            continue;
                        }
                        if(markSet.contains(cc[z][j+1])){
                            continue;
                        }
                        markSet.add(cc[z][j+1]);
                        ccList.add(cc[z][j+1]);
                    }
                }
                if(j!=k-1){
                    for(int z=i; z<i+k; ++z){
                        if(cc[z][j-k]==0){
                            continue;
                        }
                        if(markSet.contains(cc[z][j-k])){
                            continue;
                        }
                        markSet.add(cc[z][j-k]);
                        ccList.add(cc[z][j-k]);
                    }
                }
                if(i!=0){
                    for(int z=j-k;z<=j+1; ++z){
                        if((z==-1)||(z==n)){
                            continue;
                        }
                        if(cc[i-1][z]==0){
                            continue;
                        }
                        if(markSet.contains(cc[i-1][z])){
                            continue;
                        }
                        markSet.add(cc[i-1][z]);
                        ccList.add(cc[i-1][z]);

                    }
                }
                if(i!=n-k){
                    for(int z=j-k;z<=j+1; ++z){
                        if((z==-1)||(z==n)){
                            continue;
                        }
                        if(cc[i+k][z]==0){
                            continue;
                        }
                        if(markSet.contains(cc[i+k][z])){
                            continue;
                        }
                        markSet.add(cc[i+k][z]);
                        ccList.add(cc[i+k][z]);
                    }
                }
                int result = k*k;
                for(Integer item: ccList){
                    result += (totalCount[item]-count[item]);
                }

                answer = Math.max(answer,result);
                for(int z=i; z<i+k; ++z){
                    count[cc[z][j-k+1]]--;
                }
            }
        }
        out.println(answer);

    }

    public static void main(String[] args) throws Exception {
        solve();
        out.close();
    }

    private static class InputReader {
        private InputStream stream;
        private byte[] buffer;
        private int currentIndex;
        private int bytesRead;

        public InputReader(InputStream stream) {
            this.stream = stream;
            buffer = new byte[131072];
        }

        public InputReader(InputStream stream, int bufferSize) {
            this.stream = stream;
            buffer = new byte[bufferSize];
        }

        private int read() throws IOException {
            if (currentIndex >= bytesRead) {
                currentIndex = 0;
                bytesRead = stream.read(buffer);
                if (bytesRead <= 0) {
                    return -1;
                }
            }
            return buffer[currentIndex++];
        }

        public String readString() throws IOException {
            int c = read();
            while (!isPrintable(c)) {
                c = read();
            }
            StringBuilder result = new StringBuilder();
            do {
                result.appendCodePoint(c);
                c = read();
            } while (isPrintable(c));
            return result.toString();
        }

        public int readInt() throws Exception {
            int c = read();
            int sign = 1;
            while (!isPrintable(c)) {
                c = read();
            }
            if (c == '-') {
                sign = -1;
                c = read();
            }
            int result = 0;
            do {
                if ((c < '0') || (c > '9')) {
                    throw new InputMismatchException();
                }
                result *= 10;
                result += (c - '0');
                c = read();
            } while (isPrintable(c));
            return sign * result;
        }

        public long readLong() throws Exception {
            int c = read();
            int sign = 1;
            while (!isPrintable(c)) {
                c = read();
            }
            if (c == '-') {
                sign = -1;
                c = read();
            }
            long result = 0;
            do {
                if ((c < '0') || (c > '9')) {
                    throw new InputMismatchException();
                }
                result *= 10;
                result += (c - '0');
                c = read();
            } while (isPrintable(c));
            return sign * result;
        }

        public double readDouble() throws Exception {
            int c = read();
            int sign = 1;
            while (!isPrintable(c)) {
                c = read();
            }
            if (c == '-') {
                sign = -1;
                c = read();
            }
            boolean fraction = false;
            double multiplier = 1;
            double result = 0;
            do {
                if ((c == 'e') || (c == 'E')) {
                    return sign * result * Math.pow(10, readInt());
                }
                if ((c < '0') || (c > '9')) {
                    if ((c == '.') && (!fraction)) {
                        fraction = true;
                        c = read();
                        continue;
                    }
                    throw new InputMismatchException();
                }
                if (fraction) {
                    multiplier /= 10;
                    result += (c - '0') * multiplier;
                    c = read();
                } else {
                    result *= 10;
                    result += (c - '0');
                    c = read();
                }
            } while (isPrintable(c));
            return sign * result;
        }

        private boolean isPrintable(int c) {
            return ((c > 32) && (c < 127));
        }
    }

    private static class OutputWriter {
        private PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

        public void flush() {
            writer.flush();
        }
    }
}

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 * #
 * @author pttrung
 */
public class C_Round_356_Div1 {

    public static long MOD = 1000000007;
    static int[] X = {0, 1, 0, -1};
    static int[] Y = {1, 0, -1, 0};

    public static void main(String[] args) throws FileNotFoundException {
        // PrintWriter out = new PrintWriter(new FileOutputStream(new File(
        // "output.txt")));
        PrintWriter out = new PrintWriter(System.out);
        Scanner in = new Scanner();
        int n = in.nextInt();
        int k = in.nextInt();
        if (n == k) {
            out.println(n * n);
        } else {
            String[] data = new String[n];
            int[][] com = new int[n][n];
            for (int i = 0; i < n; i++) {
                data[i] = in.next();
            }
            int cur = 1;
            ArrayList<Integer> list = new ArrayList();
            list.add(0);
            int[][] total = new int[n][n];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    total[i][j] = (i > 0 ? total[i - 1][j] : 0) + (j > 0 ? total[i][j - 1] : 0) - (i > 0 && j > 0 ? total[i - 1][j - 1] : 0);
                    if (data[i].charAt(j) == '.') {

                        total[i][j]++;
                        if (com[i][j] == 0) {
                            LinkedList<Point> q = new LinkedList();
                            q.add(new Point(i, j));
                            com[i][j] = cur;
                            int count = 1;
                            while (!q.isEmpty()) {
                                Point p = q.poll();
                                for (int h = 0; h < 4; h++) {
                                    int x = p.x + X[h];
                                    int y = p.y + Y[h];
                                    if (x >= 0 && x < n && y >= 0 && y < n && com[x][y] == 0 && data[x].charAt(y) == '.') {
                                        com[x][y] = cur;
                                        count++;
                                        q.add(new Point(x, y));
                                    }
                                }
                            }
                            list.add(count);
                            cur++;
                        }
                    }
                }
            }
//        for(int[]a : com){
//            System.out.println(Arrays.toString(a));
//        }
            int result = 0;
            for (int i = 0; i + k <= n; i++) {
                for (int j = 0; j + k <= n; j++) {
                    int tmp = 0;
                    HashSet<Integer> set = new HashSet();
                    if (i > 0) {
                        for (int h = 0; h < k; h++) {
                            if (!set.contains(com[i - 1][j + h])) {
                                set.add(com[i - 1][j + h]);
                                tmp += list.get(com[i - 1][j + h]);
                            }
                        }
                    }
                    if (i + k < n) {
                        for (int h = 0; h < k; h++) {
                            if (!set.contains(com[i + k][j + h])) {
                                set.add(com[i + k][j + h]);
                                tmp += list.get(com[i + k][j + h]);
                            }
                        }
                    }
                    if (j > 0) {
                        for (int h = 0; h < k; h++) {
                            if (!set.contains(com[i + h][j - 1])) {
                                set.add(com[i + h][j - 1]);
                                tmp += list.get(com[i + h][j - 1]);
                            }
                        }
                    }
                    if (j + k < n) {
                        for (int h = 0; h < k; h++) {
                            if (!set.contains(com[i + h][j + k])) {
                                set.add(com[i + h][j + k]);
                                tmp += list.get(com[i + h][j + k]);
                            }
                        }
                    }

                    for(int h = 0; h < k; h++){
                        for(int q = 0 ; q < k ; q++){
                            if(set.contains(com[i + h][j + q])){
                                tmp--;
                            }
                        }
                    }
                    //System.out.println(tmp);
                    tmp += k * k;
                    result = Integer.max(result, tmp);
                }
            }
            out.println(result);
        }
        out.close();
    }

    public static int[] KMP(String val) {
        int i = 0;
        int j = -1;
        int[] result = new int[val.length() + 1];
        result[0] = -1;
        while (i < val.length()) {
            while (j >= 0 && val.charAt(j) != val.charAt(i)) {
                j = result[j];
            }
            j++;
            i++;
            result[i] = j;
        }
        return result;

    }

    public static boolean nextPer(int[] data) {
        int i = data.length - 1;
        while (i > 0 && data[i] < data[i - 1]) {
            i--;
        }
        if (i == 0) {
            return false;
        }
        int j = data.length - 1;
        while (data[j] < data[i - 1]) {
            j--;
        }
        int temp = data[i - 1];
        data[i - 1] = data[j];
        data[j] = temp;
        Arrays.sort(data, i, data.length);
        return true;
    }

    public static int digit(long n) {
        int result = 0;
        while (n > 0) {
            n /= 10;
            result++;
        }
        return result;
    }

    public static double dist(long a, long b, long x, long y) {
        double val = (b - a) * (b - a) + (x - y) * (x - y);
        val = Math.sqrt(val);
        double other = x * x + a * a;
        other = Math.sqrt(other);
        return val + other;

    }

    public static class Point implements Comparable<Point> {

        int x, y;

        public Point(int start, int end) {
            this.x = start;
            this.y = end;
        }

        @Override
        public int hashCode() {
            int hash = 5;
            hash = 47 * hash + this.x;
            hash = 47 * hash + this.y;
            return hash;
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final Point other = (Point) obj;
            if (this.x != other.x) {
                return false;
            }
            if (this.y != other.y) {
                return false;
            }
            return true;
        }

        @Override
        public int compareTo(Point o) {
            return Integer.compare(x, o.x);
        }
    }

    public static class FT {

        long[] data;

        FT(int n) {
            data = new long[n];
        }

        public void update(int index, long value) {
            while (index < data.length) {
                data[index] += value;
                index += (index & (-index));
            }
        }

        public long get(int index) {
            long result = 0;
            while (index > 0) {
                result += data[index];
                index -= (index & (-index));
            }
            return result;

        }
    }

    public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    public static long pow(long a, long b, long MOD) {
        if (b == 0) {
            return 1;
        }
        if (b == 1) {
            return a;
        }
        long val = pow(a, b / 2, MOD);
        if (b % 2 == 0) {
            return val * val % MOD;
        } else {
            return val * (val * a % MOD) % MOD;

        }
    }

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() throws FileNotFoundException {
            // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
            //  br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt"))));
        }

        public String next() {

            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 * #
 * @author pttrung
 */
public class C_Round_356_Div1 {

    public static long MOD = 1000000007;
    static int[] X = {0, 1, 0, -1};
    static int[] Y = {1, 0, -1, 0};

    public static void main(String[] args) throws FileNotFoundException {
        // PrintWriter out = new PrintWriter(new FileOutputStream(new File(
        // "output.txt")));
        PrintWriter out = new PrintWriter(System.out);
        Scanner in = new Scanner();
        int n = in.nextInt();
        int k = in.nextInt();
        String[] data = new String[n];
        int[][] com = new int[n][n];
        for (int i = 0; i < n; i++) {
            data[i] = in.next();
        }
        int cur = 1;
        ArrayList<Integer> list = new ArrayList();
        list.add(0);
        int[][] total = new int[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                total[i][j] = (i > 0 ? total[i - 1][j] : 0) + (j > 0 ? total[i][j - 1] : 0) - (i > 0 && j > 0 ? total[i - 1][j - 1] : 0);
                if (data[i].charAt(j) == '.') {

                    total[i][j]++;
                    if (com[i][j] == 0) {
                        LinkedList<Point> q = new LinkedList();
                        q.add(new Point(i, j));
                        com[i][j] = cur;
                        int count = 1;
                        while (!q.isEmpty()) {
                            Point p = q.poll();
                            for (int h = 0; h < 4; h++) {
                                int x = p.x + X[h];
                                int y = p.y + Y[h];
                                if (x >= 0 && x < n && y >= 0 && y < n && com[x][y] == 0 && data[x].charAt(y) == '.') {
                                    com[x][y] = cur;
                                    count++;
                                    q.add(new Point(x, y));
                                }
                            }
                        }
                        list.add(count);
                        cur++;
                    }
                }
            }
        }
//        for(int[]a : com){
//            System.out.println(Arrays.toString(a));
//        }
        int result = 0;
        for (int i = 0; i + k <= n; i++) {
            for (int j = 0; j + k <= n; j++) {
                int tmp = 0;
                HashSet<Integer> set = new HashSet();
                if (i > 0) {
                    for (int h = 0; h < k; h++) {
                        if (!set.contains(com[i - 1][j + h])) {
                            set.add(com[i - 1][j + h]);
                            tmp += list.get(com[i - 1][j + h]);
                        }
                    }
                }
                if (i + k < n) {
                    for (int h = 0; h < k; h++) {
                        if (!set.contains(com[i + k][j + h])) {
                            set.add(com[i + k][j + h]);
                            tmp += list.get(com[i + k][j + h]);
                        }
                    }
                }
                if (j > 0) {
                    for (int h = 0; h < k; h++) {
                        if (!set.contains(com[i + h][j - 1])) {
                            set.add(com[i + h][j - 1]);
                            tmp += list.get(com[i + h][j - 1]);
                        }
                    }
                }
                if (j + k < n) {
                    for (int h = 0; h < k; h++) {
                        if (!set.contains(com[i + h][j + k])) {
                            set.add(com[i + h][j + k]);
                            tmp += list.get(com[i + h][j + k]);
                        }
                    }
                }
                tmp -= (total[i + k - 1][j + k - 1] - (i > 0 ? total[i - 1][j + k - 1] : 0) - (j > 0 ? total[i + k - 1][j - 1] : 0) + (i > 0 && j > 0 ? total[i - 1][j - 1] : 0));
                tmp += k*k;
                result = Integer.max(result, tmp);
            }
        }
        out.println(result);
        out.close();
    }

    public static int[] KMP(String val) {
        int i = 0;
        int j = -1;
        int[] result = new int[val.length() + 1];
        result[0] = -1;
        while (i < val.length()) {
            while (j >= 0 && val.charAt(j) != val.charAt(i)) {
                j = result[j];
            }
            j++;
            i++;
            result[i] = j;
        }
        return result;

    }

    public static boolean nextPer(int[] data) {
        int i = data.length - 1;
        while (i > 0 && data[i] < data[i - 1]) {
            i--;
        }
        if (i == 0) {
            return false;
        }
        int j = data.length - 1;
        while (data[j] < data[i - 1]) {
            j--;
        }
        int temp = data[i - 1];
        data[i - 1] = data[j];
        data[j] = temp;
        Arrays.sort(data, i, data.length);
        return true;
    }

    public static int digit(long n) {
        int result = 0;
        while (n > 0) {
            n /= 10;
            result++;
        }
        return result;
    }

    public static double dist(long a, long b, long x, long y) {
        double val = (b - a) * (b - a) + (x - y) * (x - y);
        val = Math.sqrt(val);
        double other = x * x + a * a;
        other = Math.sqrt(other);
        return val + other;

    }

    public static class Point implements Comparable<Point> {

        int x, y;

        public Point(int start, int end) {
            this.x = start;
            this.y = end;
        }

        @Override
        public int hashCode() {
            int hash = 5;
            hash = 47 * hash + this.x;
            hash = 47 * hash + this.y;
            return hash;
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final Point other = (Point) obj;
            if (this.x != other.x) {
                return false;
            }
            if (this.y != other.y) {
                return false;
            }
            return true;
        }

        @Override
        public int compareTo(Point o) {
            return Integer.compare(x, o.x);
        }
    }

    public static class FT {

        long[] data;

        FT(int n) {
            data = new long[n];
        }

        public void update(int index, long value) {
            while (index < data.length) {
                data[index] += value;
                index += (index & (-index));
            }
        }

        public long get(int index) {
            long result = 0;
            while (index > 0) {
                result += data[index];
                index -= (index & (-index));
            }
            return result;

        }
    }

    public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    public static long pow(long a, long b, long MOD) {
        if (b == 0) {
            return 1;
        }
        if (b == 1) {
            return a;
        }
        long val = pow(a, b / 2, MOD);
        if (b % 2 == 0) {
            return val * val % MOD;
        } else {
            return val * (val * a % MOD) % MOD;

        }
    }

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() throws FileNotFoundException {
            // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
            //  br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt"))));
        }

        public String next() {

            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 * #
 * @author pttrung
 */
public class C_Round_356_Div1 {

    public static long MOD = 1000000007;
    static int[] X = {0, 1, 0, -1};
    static int[] Y = {1, 0, -1, 0};

    public static void main(String[] args) throws FileNotFoundException {
        // PrintWriter out = new PrintWriter(new FileOutputStream(new File(
        // "output.txt")));
        PrintWriter out = new PrintWriter(System.out);
        Scanner in = new Scanner();
        int n = in.nextInt();
        int k = in.nextInt();
        if (n == k) {
            out.println(n * n);
        } else {
            String[] data = new String[n];
            int[][] com = new int[n][n];
            for (int i = 0; i < n; i++) {
                data[i] = in.next();
            }
            int cur = 1;
            ArrayList<Integer> list = new ArrayList();
            list.add(0);
            int[][] total = new int[n][n];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    total[i][j] = (i > 0 ? total[i - 1][j] : 0) + (j > 0 ? total[i][j - 1] : 0) - (i > 0 && j > 0 ? total[i - 1][j - 1] : 0);
                    if (data[i].charAt(j) == '.') {

                        total[i][j]++;
                        if (com[i][j] == 0) {
                            LinkedList<Point> q = new LinkedList();
                            q.add(new Point(i, j));
                            com[i][j] = cur;
                            int count = 1;
                            while (!q.isEmpty()) {
                                Point p = q.poll();
                                for (int h = 0; h < 4; h++) {
                                    int x = p.x + X[h];
                                    int y = p.y + Y[h];
                                    if (x >= 0 && x < n && y >= 0 && y < n && com[x][y] == 0 && data[x].charAt(y) == '.') {
                                        com[x][y] = cur;
                                        count++;
                                        q.add(new Point(x, y));
                                    }
                                }
                            }
                            list.add(count);
                            cur++;
                        }
                    }
                }
            }
//        for(int[]a : com){
//            System.out.println(Arrays.toString(a));
//        }
            int result = 0;
            for (int i = 0; i + k <= n; i++) {
                for (int j = 0; j + k <= n; j++) {
                    int tmp = 0;
                    HashSet<Integer> set = new HashSet();
                    if (i > 0) {
                        for (int h = 0; h < k; h++) {
                            if (!set.contains(com[i - 1][j + h])) {
                                set.add(com[i - 1][j + h]);
                                tmp += list.get(com[i - 1][j + h]);
                            }
                        }
                    }
                    if (i + k < n) {
                        for (int h = 0; h < k; h++) {
                            if (!set.contains(com[i + k][j + h])) {
                                set.add(com[i + k][j + h]);
                                tmp += list.get(com[i + k][j + h]);
                            }
                        }
                    }
                    if (j > 0) {
                        for (int h = 0; h < k; h++) {
                            if (!set.contains(com[i + h][j - 1])) {
                                set.add(com[i + h][j - 1]);
                                tmp += list.get(com[i + h][j - 1]);
                            }
                        }
                    }
                    if (j + k < n) {
                        for (int h = 0; h < k; h++) {
                            if (!set.contains(com[i + h][j + k])) {
                                set.add(com[i + h][j + k]);
                                tmp += list.get(com[i + h][j + k]);
                            }
                        }
                    }

                    tmp -= (total[i + k - 1][j + k - 1] - (i > 0 ? total[i - 1][j + k - 1] : 0) - (j > 0 ? total[i + k - 1][j - 1] : 0) + (i > 0 && j > 0 ? total[i - 1][j - 1] : 0));
                    //System.out.println(tmp);
                    tmp += k * k;
                    result = Integer.max(result, tmp);
                }
            }
            out.println(result);
        }
        out.close();
    }

    public static int[] KMP(String val) {
        int i = 0;
        int j = -1;
        int[] result = new int[val.length() + 1];
        result[0] = -1;
        while (i < val.length()) {
            while (j >= 0 && val.charAt(j) != val.charAt(i)) {
                j = result[j];
            }
            j++;
            i++;
            result[i] = j;
        }
        return result;

    }

    public static boolean nextPer(int[] data) {
        int i = data.length - 1;
        while (i > 0 && data[i] < data[i - 1]) {
            i--;
        }
        if (i == 0) {
            return false;
        }
        int j = data.length - 1;
        while (data[j] < data[i - 1]) {
            j--;
        }
        int temp = data[i - 1];
        data[i - 1] = data[j];
        data[j] = temp;
        Arrays.sort(data, i, data.length);
        return true;
    }

    public static int digit(long n) {
        int result = 0;
        while (n > 0) {
            n /= 10;
            result++;
        }
        return result;
    }

    public static double dist(long a, long b, long x, long y) {
        double val = (b - a) * (b - a) + (x - y) * (x - y);
        val = Math.sqrt(val);
        double other = x * x + a * a;
        other = Math.sqrt(other);
        return val + other;

    }

    public static class Point implements Comparable<Point> {

        int x, y;

        public Point(int start, int end) {
            this.x = start;
            this.y = end;
        }

        @Override
        public int hashCode() {
            int hash = 5;
            hash = 47 * hash + this.x;
            hash = 47 * hash + this.y;
            return hash;
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final Point other = (Point) obj;
            if (this.x != other.x) {
                return false;
            }
            if (this.y != other.y) {
                return false;
            }
            return true;
        }

        @Override
        public int compareTo(Point o) {
            return Integer.compare(x, o.x);
        }
    }

    public static class FT {

        long[] data;

        FT(int n) {
            data = new long[n];
        }

        public void update(int index, long value) {
            while (index < data.length) {
                data[index] += value;
                index += (index & (-index));
            }
        }

        public long get(int index) {
            long result = 0;
            while (index > 0) {
                result += data[index];
                index -= (index & (-index));
            }
            return result;

        }
    }

    public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    public static long pow(long a, long b, long MOD) {
        if (b == 0) {
            return 1;
        }
        if (b == 1) {
            return a;
        }
        long val = pow(a, b / 2, MOD);
        if (b % 2 == 0) {
            return val * val % MOD;
        } else {
            return val * (val * a % MOD) % MOD;

        }
    }

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() throws FileNotFoundException {
            // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
            //  br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt"))));
        }

        public String next() {

            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}

import java.io.*;
import java.util.*;

public class C {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	int n;
	int k;

	char[][] f;

	int[][] color;
	List<Integer> sizeAL;

	int[] size;

	static final int[] DX = { -1, 0, 1, 0 };
	static final int[] DY = { 0, -1, 0, 1 };

	int dfs(int x, int y, int cur) {
		color[x][y] = cur;
		int ret = 1;
		for (int d = 0; d < 4; d++) {
			int cx = x + DX[d];
			int cy = y + DY[d];
			if (cx >= 0 && cx < n && cy >= 0 && cy < n && f[cx][cy] == '.'
					&& color[cx][cy] == 0) {
				ret += dfs(cx, cy, cur);
			}
		}
		return ret;
	}

	static class Counter {
		int[] count;
		int[] score;

		int sum = 0;

		void modify(int idx, int delta) {
			if (count[idx] != 0) {
				sum -= score[idx];
			}
			count[idx] += delta;
			if (count[idx] != 0) {
				sum += score[idx];
			}
		}

		int getSum() {
			return sum;
		}

		void clear() {
			Arrays.fill(count, 0);
			sum = 0;
		}

		public Counter(int[] score) {
			this.score = score;
			count = new int[score.length];
		}

	}

	void solve() throws IOException {
		n = nextInt();
		k = nextInt();

		f = new char[n][];
		for (int i = 0; i < n; i++) {
			f[i] = nextToken().toCharArray();
		}

		color = new int[n][n];
		sizeAL = new ArrayList<>();

		int comps = 0;

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (f[i][j] == '.' && color[i][j] == 0) {
					comps++;
					sizeAL.add(dfs(i, j, comps));
				}
			}
		}

		size = new int[comps];
		for (int i = 0; i < comps; i++) {
			size[i] = sizeAL.get(i);
		}

//		System.err.println(Arrays.deepToString(color));
//		System.err.println(Arrays.toString(size));

		Counter counter = new Counter(size);

		int ans = -1;

		for (int top = 0; top <= n - k; top++) {

			counter.clear();
			int xs = 0;

			for (int x = top - 1; x < top + k + 1; x++)
				for (int y = 0; y < k + 1 && y < n; y++) {

					if (x < 0 || x >= n) {
						continue;
					}

					int status = ((x == top - 1 || x == top + k) ? 1 : 0)
							+ (y == k ? 1 : 0);

					if (status == 2) {
						continue;
					}

					if (color[x][y] != 0) {
						counter.modify(color[x][y] - 1, 1);
					} else {
						if (status == 0) {
							xs++;
						}
					}
				}

			int value = counter.getSum() + xs;
//			System.err.println(value - xs);
//			System.err.println(xs);
//			System.err.println("--------");
			ans = Math.max(ans, value);

			for (int left = 1; left <= n - k; left++) {

				// update counter
				for (int x = top - 1; x <= top + k; x++) {
					if (x < 0 || x >= n) {
						continue;
					}
					int y1 = (x == top - 1 || x == top + k) ? left : left - 1;
					if (y1 >= 0 && y1 < n && color[x][y1] != 0) {
						counter.modify(color[x][y1] - 1, -1);
					}

					int y2 = (x == top - 1 || x == top + k) ? left + k - 1
							: left + k;
					if (y2 >= 0 && y2 < n && color[x][y2] != 0) {
						counter.modify(color[x][y2] - 1, 1);
					}
				}

				// update xs
				for (int x = top; x < top + k; x++) {
					if (color[x][left - 1] == 0) {
						xs--;
					}
					if (left + k - 1 < n && color[x][left + k - 1] == 0) {
						xs++;
					}
				}

				value = counter.getSum() + xs;
//				System.err.println(value);
				ans = Math.max(ans, value);

			}

		}

		out.println(ans);
	}

	C() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new C();
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return null;
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Set;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.FileNotFoundException;
import java.io.File;
import java.util.HashSet;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.UnsupportedEncodingException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author shu_mj @ http://shu-mj.com
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        Printer out = new Printer(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        Scanner in;
        Printer out;
        int[] dx = {0, 0, 1, -1};
        int[] dy = {1, -1, 0, 0};

        public void solve(int testNumber, Scanner in, Printer out) {
            this.in = in;
            this.out = out;
            run();
        }

        void run() {
            int n = in.nextInt();
            int k = in.nextInt();
            char[][] maps = in.nextCharMatrix(n);
            int[][] id = new int[n][n];
            Sequence.fill(id, -1);
            int ic = 0;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if (maps[i][j] == '.' && id[i][j] == -1) {
                        dfs(maps, id, i, j, ic++);
                    }
                }
            }
            int[] cnt = new int[ic];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if (id[i][j] != -1) {
                        cnt[id[i][j]]++;
                    }
                }
            }
            int res = 0;
            for (int i = 0; i + k <= n; i++) {
                int[] inc = new int[ic];
                int ri = 0;
                for (int u = 0; u < k; u++) {
                    for (int v = 0; v < k; v++) {
                        int ie = id[i + u][v];
                        if (ie != -1) {
                            if (inc[ie] == 0) ri += cnt[ie];
                            inc[ie]++;
                            ri--;
                        }
                    }
                }
                res = Math.max(res, ri);
                for (int j = 0; j + k < n; j++) {
                    for (int u = 0; u < k; u++) {
                        int ie = id[i + u][j];
                        if (ie != -1) {
                            inc[ie]--;
                            ri++;
                            if (inc[ie] == 0) ri -= cnt[ie];
                        }
                    }
                    for (int u = 0; u < k; u++) {
                        int ie = id[i + u][j + k];
                        if (ie != -1) {
                            if (inc[ie] == 0) ri += cnt[ie];
                            inc[ie]++;
                            ri--;
                        }
                    }
                    Set<Integer> vis = new HashSet<>();
                    int tmp = 0;
                    tmp += go(id, cnt, inc, vis, k, i, j, 1, 0);
                    tmp += go(id, cnt, inc, vis, k, i, j + k + 1, 1, 0);
                    tmp += go(id, cnt, inc, vis, k, i - 1, j + 1, 0, 1);
                    tmp += go(id, cnt, inc, vis, k, i + k, j + 1, 0, 1);
                    tmp += check(id, cnt, inc, vis, i - 1, j);
                    tmp += check(id, cnt, inc, vis, i - 1, j + k + 1);
                    tmp += check(id, cnt, inc, vis, i + k, j);
                    tmp += check(id, cnt, inc, vis, i + k, j + k + 1);
                    res = Math.max(res, ri + tmp);
                }
            }
            out.println(res + k * k);
        }

        private int check(int[][] id, int[] cnt, int[] inc, Set<Integer> vis, int x, int y) {
            if (x >= 0 && y >= 0 && x < id.length && y < id[0].length) {
                int ie = id[x][y];
                if (ie != -1 && inc[ie] == 0 && !vis.contains(ie)) {
                    vis.add(ie);
                    return cnt[ie];
                }
            }
            return 0;
        }

        private int go(int[][] id, int[] cnt, int[] inc, Set<Integer> vis, int k, int i, int j, int di, int dj) {
            int res = 0;
            for (int u = 0; u < k; u++) {
                int x = i + di * u;
                int y = j + dj * u;
                res += check(id, cnt, inc, vis, x, y);
            }
            return res;
        }

        private void dfs(char[][] maps, int[][] id, int r, int c, int ic) {
            id[r][c] = ic;
            for (int i = 0; i < 4; i++) {
                int x = r + dx[i];
                int y = c + dy[i];
                if (x >= 0 && y >= 0 && x < maps.length && y < maps[0].length) {
                    if (maps[x][y] == '.' && id[x][y] == -1) {
                        dfs(maps, id, x, y, ic);
                    }
                }
            }
        }

    }

    static class Scanner {
        BufferedReader br;
        StringTokenizer st;

        public Scanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
            eat("");
        }

        private void eat(String s) {
            st = new StringTokenizer(s);
        }

        public String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                return null;
            }
        }

        public boolean hasNext() {
            while (!st.hasMoreTokens()) {
                String s = nextLine();
                if (s == null)
                    return false;
                eat(s);
            }
            return true;
        }

        public String next() {
            hasNext();
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public char[] nextCharArray() {
            return next().toCharArray();
        }

        public char[][] nextCharMatrix(int row) {
            char[][] mat = new char[row][];
            for (int i = 0; i < row; i++) {
                mat[i] = nextCharArray();
            }
            return mat;
        }

    }

    static class Printer extends PrintWriter {
        public Printer(Writer out) {
            super(out);
        }

        public Printer(Writer out, boolean autoFlush) {
            super(out, autoFlush);
        }

        public Printer(OutputStream out) {
            super(out);
        }

        public Printer(OutputStream out, boolean autoFlush) {
            super(out, autoFlush);
        }

        public Printer(String fileName) throws FileNotFoundException {
            super(fileName);
        }

        public Printer(String fileName, String csn) throws FileNotFoundException, UnsupportedEncodingException {
            super(fileName, csn);
        }

        public Printer(File file) throws FileNotFoundException {
            super(file);
        }

        public Printer(File file, String csn) throws FileNotFoundException, UnsupportedEncodingException {
            super(file, csn);
        }

    }

    static class Sequence {
        public static void fill(int[][] a, int v) {
            for (int[] b : a) {
                fill(b, v);
            }
        }

        public static void fill(int[] a, int v) {
            Arrays.fill(a, v);
        }

    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Set;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.FileNotFoundException;
import java.io.File;
import java.util.HashSet;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.UnsupportedEncodingException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author shu_mj @ http://shu-mj.com
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        Printer out = new Printer(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        Scanner in;
        Printer out;
        int[] dx = {0, 0, 1, -1};
        int[] dy = {1, -1, 0, 0};

        public void solve(int testNumber, Scanner in, Printer out) {
            this.in = in;
            this.out = out;
            run();
        }

        void run() {
            int n = in.nextInt();
            int k = in.nextInt();
            char[][] maps = in.nextCharMatrix(n);
            int[][] id = new int[n][n];
            Sequence.fill(id, -1);
            int ic = 0;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if (maps[i][j] == '.' && id[i][j] == -1) {
                        dfs(maps, id, i, j, ic++);
                    }
                }
            }
            int[] cnt = new int[ic];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if (id[i][j] != -1) {
                        cnt[id[i][j]]++;
                    }
                }
            }
            int res = 0;
            for (int i = 0; i + k <= n; i++) {
                int[] inc = new int[ic];
                int ri = 0;
                for (int u = 0; u < k; u++) {
                    for (int v = 0; v < k; v++) {
                        int ie = id[i + u][v];
                        if (ie != -1) {
                            if (inc[ie] == 0) ri += cnt[ie];
                            inc[ie]++;
                            ri--;
                        }
                    }
                }
                {
                    Set<Integer> vis = new HashSet<>();
                    int tmp = 0;
                    tmp += go(id, cnt, inc, vis, k, i, k, 1, 0);
                    tmp += go(id, cnt, inc, vis, k, i - 1, 0, 0, 1);
                    tmp += go(id, cnt, inc, vis, k, i + k, 0, 0, 1);
                    tmp += check(id, cnt, inc, vis, i - 1, k);
                    tmp += check(id, cnt, inc, vis, i + k, k);
                    res = Math.max(res, ri + tmp);
                }
                for (int j = 0; j + k < n; j++) {
                    for (int u = 0; u < k; u++) {
                        int ie = id[i + u][j];
                        if (ie != -1) {
                            inc[ie]--;
                            ri++;
                            if (inc[ie] == 0) ri -= cnt[ie];
                        }
                    }
                    for (int u = 0; u < k; u++) {
                        int ie = id[i + u][j + k];
                        if (ie != -1) {
                            if (inc[ie] == 0) ri += cnt[ie];
                            inc[ie]++;
                            ri--;
                        }
                    }
                    Set<Integer> vis = new HashSet<>();
                    int tmp = 0;
                    tmp += go(id, cnt, inc, vis, k, i, j, 1, 0);
                    tmp += go(id, cnt, inc, vis, k, i, j + k + 1, 1, 0);
                    tmp += go(id, cnt, inc, vis, k, i - 1, j + 1, 0, 1);
                    tmp += go(id, cnt, inc, vis, k, i + k, j + 1, 0, 1);
                    tmp += check(id, cnt, inc, vis, i - 1, j);
                    tmp += check(id, cnt, inc, vis, i - 1, j + k + 1);
                    tmp += check(id, cnt, inc, vis, i + k, j);
                    tmp += check(id, cnt, inc, vis, i + k, j + k + 1);
                    res = Math.max(res, ri + tmp);
                }
            }
            out.println(res + k * k);
        }

        private int check(int[][] id, int[] cnt, int[] inc, Set<Integer> vis, int x, int y) {
            if (x >= 0 && y >= 0 && x < id.length && y < id[0].length) {
                int ie = id[x][y];
                if (ie != -1 && inc[ie] == 0 && !vis.contains(ie)) {
                    vis.add(ie);
                    return cnt[ie];
                }
            }
            return 0;
        }

        private int go(int[][] id, int[] cnt, int[] inc, Set<Integer> vis, int k, int i, int j, int di, int dj) {
            int res = 0;
            for (int u = 0; u < k; u++) {
                int x = i + di * u;
                int y = j + dj * u;
                res += check(id, cnt, inc, vis, x, y);
            }
            return res;
        }

        private void dfs(char[][] maps, int[][] id, int r, int c, int ic) {
            id[r][c] = ic;
            for (int i = 0; i < 4; i++) {
                int x = r + dx[i];
                int y = c + dy[i];
                if (x >= 0 && y >= 0 && x < maps.length && y < maps[0].length) {
                    if (maps[x][y] == '.' && id[x][y] == -1) {
                        dfs(maps, id, x, y, ic);
                    }
                }
            }
        }

    }

    static class Scanner {
        BufferedReader br;
        StringTokenizer st;

        public Scanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
            eat("");
        }

        private void eat(String s) {
            st = new StringTokenizer(s);
        }

        public String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                return null;
            }
        }

        public boolean hasNext() {
            while (!st.hasMoreTokens()) {
                String s = nextLine();
                if (s == null)
                    return false;
                eat(s);
            }
            return true;
        }

        public String next() {
            hasNext();
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public char[] nextCharArray() {
            return next().toCharArray();
        }

        public char[][] nextCharMatrix(int row) {
            char[][] mat = new char[row][];
            for (int i = 0; i < row; i++) {
                mat[i] = nextCharArray();
            }
            return mat;
        }

    }

    static class Printer extends PrintWriter {
        public Printer(Writer out) {
            super(out);
        }

        public Printer(Writer out, boolean autoFlush) {
            super(out, autoFlush);
        }

        public Printer(OutputStream out) {
            super(out);
        }

        public Printer(OutputStream out, boolean autoFlush) {
            super(out, autoFlush);
        }

        public Printer(String fileName) throws FileNotFoundException {
            super(fileName);
        }

        public Printer(String fileName, String csn) throws FileNotFoundException, UnsupportedEncodingException {
            super(fileName, csn);
        }

        public Printer(File file) throws FileNotFoundException {
            super(file);
        }

        public Printer(File file, String csn) throws FileNotFoundException, UnsupportedEncodingException {
            super(file, csn);
        }

    }

    static class Sequence {
        public static void fill(int[][] a, int v) {
            for (int[] b : a) {
                fill(b, v);
            }
        }

        public static void fill(int[] a, int v) {
            Arrays.fill(a, v);
        }

    }
}

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Set;

public class Round356_E_postContest_v2 {

    static final int WALL = 0;
    static final int EMPTY_NOT_DISCOVERED = -1;

    public static void main(String[] args) throws IOException {
        FastReader in = new FastReader(System.in);
        PrintWriter out = new PrintWriter(System.out);

        // read input

        int n = in.readInt();
        int k = in.readInt();

        int[][] grid = new int[n][n];
        for (int i = 0 ; i < n ; i++) {
            for (int j = 0 ; j < n ; j++) {
                char c = in.readChar();
                grid[i][j] = (c == '.') ? EMPTY_NOT_DISCOVERED : WALL;
            }
        }

        // find components
        int components = 0;
        for (int i = 0 ; i < n ; i++) {
            for (int j = 0 ; j < n ; j++) {
                if (grid[i][j] == EMPTY_NOT_DISCOVERED) {
                    discover(grid, i, j, ++components);
                }
            }
        }
        // each grid[i][j] cell now holds either 0 (WALL) or number of the component (1..x)

        // compute component sizes
        int[] componentSize = new int[components + 1];
        for (int i = 0 ; i < n ; i++) {
            for (int j = 0 ; j < n ; j++) {
                if (grid[i][j] != WALL) {
                    componentSize[grid[i][j]]++;
                }
            }
        }

        // initialize window
        int insideTotal = 0;
        int[] outside = Arrays.copyOf(componentSize, componentSize.length);
        for (int i = 0 ; i < k ; i++) {
            for (int j = 0 ; j < k ; j++) {
                if (grid[i][j] != WALL) {
                    insideTotal++;
                    outside[grid[i][j]]--;
                }
            }
        }

        // ...and move the window across board
        int xTop = 0;
        int yTop = 0;
        int dx = +1;
        int solution = 0;
        int[] flags = new int[components + 1];
        int flag = 0;
        while (true) {

            flag++;
            int cur = k*k;
            for (int off = 0 ; off < k ; off++) {
                if (xTop - 1 >= 0) {
                    int comp = grid[xTop - 1][yTop + off];
                    if (comp != WALL && flags[comp] != flag) {
                        cur += outside[comp];
                        flags[comp] = flag;
                    }
                }
                if (xTop + k < n) {
                    int comp = grid[xTop + k][yTop + off];
                    if (comp != WALL && flags[comp] != flag) {
                        cur += outside[comp];
                        flags[comp] = flag;
                    }
                }
                if (yTop - 1 >= 0) {
                    int comp = grid[xTop + off][yTop - 1];
                    if (comp != WALL && flags[comp] != flag) {
                        cur += outside[comp];
                        flags[comp] = flag;
                    }
                }
                if (yTop + k < n) {
                    int comp = grid[xTop + off][yTop + k];
                    if (comp != WALL && flags[comp] != flag) {
                        cur += outside[comp];
                        flags[comp] = flag;
                    }
                }
            }
            solution = Math.max(solution, cur);

            boolean moveRight = dx == +1 && (xTop + k + 1 <= n);
            boolean moveLeft  = dx == -1 && (xTop - 1 >= 0);
            boolean moveDown  = !moveRight && !moveLeft;
            if (moveRight) {
                for (int off = 0; off < k; off++) {
                    if (grid[xTop][yTop + off] != WALL) {
                        outside[grid[xTop][yTop + off]]++;
                    }
                    if (xTop + k < n && grid[xTop + k][yTop + off] != WALL) {
                        outside[grid[xTop + k][yTop + off]]--;
                    }
                }
                xTop++;
            } else if (moveLeft) {
                for (int off = 0 ; off < k ; off++) {
                    if (grid[xTop + k - 1][yTop + off] != WALL) {
                        outside[grid[xTop + k - 1][yTop + off]]++;
                    }
                    if (xTop - 1 >= 0 && grid[xTop - 1][yTop + off] != WALL) {
                        outside[grid[xTop - 1][yTop + off]]--;
                    }
                }
                xTop--;
            } else {
                if (yTop + k + 1 > n) {
                    break;
                }

                for (int off = 0 ; off < k ; off++) {
                    if (grid[xTop + off][yTop] != WALL) {
                        outside[grid[xTop + off][yTop]]++;
                    }
                    if (yTop + k < n && grid[xTop + off][yTop + off] != WALL) {
                        outside[grid[xTop + off][yTop + k]]--;
                    }
                }
                dx *= -1;
                yTop++;
            }
        }

        out.println(solution);
        out.flush();
    }

    private static void discover(int[][] grid, int i, int j, int componentNo) {
        int n = grid.length;
        LinkedList<int[]> open = new LinkedList<>();

        grid[i][j] = componentNo;
        open.add(new int[] {i,j});

        while (!open.isEmpty()) {
            int[] xy = open.removeFirst();
            int x = xy[0];
            int y = xy[1];

            for (int[] xxyy : new int[][] {{x-1, y}, {x+1,y}, {x,y+1}, {x,y-1}}) {
                int xx = xxyy[0];
                int yy = xxyy[1];
                if (0 <= xx && xx < n && 0 <= yy && yy < n) {
                    if (grid[xx][yy] == EMPTY_NOT_DISCOVERED) {
                        grid[xx][yy] = componentNo;
                        open.add(new int[] {xx, yy});
                    }
                }
            }
        }
    }

    private static void add(int[] cntPerComponent, Set<Integer> nonZeroCntComponents, int[][] grid, int i, int j) {
        if (isValid(grid, i, j) && grid[i][j] != WALL) {
            if (cntPerComponent[grid[i][j]]++ == 0) {
                nonZeroCntComponents.add(grid[i][j]);
            }
        }
    }

    private static void remove(int[] cntPerComponent, Set<Integer> nonZeroCntComponents, int[][] grid, int i, int j) {
        if (isValid(grid, i, j) && grid[i][j] != WALL) {
            if (--cntPerComponent[grid[i][j]] == 0) {
                nonZeroCntComponents.remove(grid[i][j]);
            }
        }
    }

    private static boolean isValid(int[][] grid, int i, int j) {
        int n = grid.length;
        return (0 <= i && i < n && 0 <= j && j < n);
    }

    /**
     * Custom buffered reader. Faster than Scanner and
     * BufferedReader + StringTokenizer.
     */
    static class FastReader {
        private final InputStream stream;
        private int current;
        private int size;
        private byte[] buffer = new byte[1024 * 8];

        public FastReader(InputStream stream) {
            this.stream = stream;
            current = 0;
            size = 0;
        }

        public int readInt() {
            int sign = 1;
            int abs = 0;
            int c = readNonEmpty();
            if (c == '-') {
                sign = -1;
                c = readAny();
            }
            do {
                if (c < '0' || c > '9') {
                    throw new IllegalStateException();
                }
                abs = 10 * abs + (c - '0');
                c = readAny();
            } while (!isEmpty(c));
            return sign * abs;
        }

        public int[] readIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0 ; i < n ; i++) {
                array[i] = readInt();
            }
            return array;
        }

        public char readChar() {
            return (char) readNonEmpty();
        }

        public String readString() {
            StringBuffer sb = new StringBuffer();
            int c;
            do {
                c = readAny();
            } while (isEmpty(c));
            do {
                sb.append((char) c);
                c = readAny();
            } while (!isEmpty(c));
            return sb.toString();
        }

        private int readAny() {
            try {
                if (current >= size) {
                    current = 0;
                    size = stream.read(buffer);
                    if (size < 0) {
                        return -1;
                    }
                }
            } catch (IOException e) {
                throw new RuntimeException("Failed to readAny next byte", e);
            }
            return buffer[current++];
        }

        private int readNonEmpty() {
            int result;
            do {
                result = readAny();
            } while (isEmpty(result));
            return result;
        }

        private static boolean isEmpty(int c) {
            return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == -1;
        }
    }
}