#include <bits/stdc++.h>
using namespace std;
const int N = 601;
int n, k, i, j, l, color[N][N], ans, cnt, g[N][N], s[1000000], sum[1000000],
    Ans;
char ch[N][N];
void dfs(int x, int y, int z) {
  if (ch[x][y] != '.') return;
  if (color[x][y]) return;
  color[x][y] = z;
  s[z]++;
  dfs(x + 1, y, z);
  dfs(x, y + 1, z);
  dfs(x - 1, y, z);
  dfs(x, y - 1, z);
}
int check(int x, int y, int ans) {
  if (color[x][y]) {
    sum[color[x][y]]--;
    if (sum[color[x][y]] == 0) ans -= s[color[x][y]];
  }
  if (color[x + l + 1][y + l + 1]) {
    sum[color[x + l + 1][y + l + 1]]--;
    if (sum[color[x + l + 1][y + l + 1]] == 0)
      ans -= s[color[x + l + 1][y + l + 1]];
  }
  if (color[x + l + 1][y]) {
    sum[color[x + l + 1][y]]--;
    if (sum[color[x + l + 1][y]] == 0) ans -= s[color[x + l + 1][y]];
  }
  if (color[x][y + l + 1]) {
    sum[color[x][y + l + 1]]--;
    if (sum[color[x][y + l + 1]] == 0) ans -= s[color[x][y + l + 1]];
  }
  if (color[x][y]) sum[color[x][y]]++;
  if (color[x][y + l + 1]) sum[color[x][y + l + 1]]++;
  if (color[x + l + 1][y]) sum[color[x + l + 1][y]]++;
  if (color[x + l + 1][y + l + 1]) sum[color[x + l + 1][y + l + 1]]++;
  return ans;
}
int main() {
  scanf("%d%d", &n, &l);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++) scanf(" %c", &ch[i][j]);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++)
      if ((ch[i][j] == '.') && (color[i][j] == 0)) dfs(i, j, ++cnt);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++) {
      g[i][j] = g[i - 1][j] + g[i][j - 1] - g[i - 1][j - 1];
      if (ch[i][j] == 'X') g[i][j]++;
    }
  for (i = 1; i <= n - l + 1; i++) {
    for (j = 1; j <= cnt; j++) sum[j] = 0;
    ans = 0;
    for (k = 0; k <= n + 1; k++) {
      for (j = i - 1; j <= i + l; j++) {
        if (color[j][k]) {
          sum[color[j][k]]++;
          if (sum[color[j][k]] == 1) ans += s[color[j][k]];
        }
        if (k - l - 2 >= 0)
          if (color[j][k - l - 2]) {
            sum[color[j][k - l - 2]]--;
            if (sum[color[j][k - l - 2]] == 0) ans -= s[color[j][k - l - 2]];
          }
      }
      if (k >= l + 1)
        Ans = max(Ans, check(i - 1, k - 1 - l, ans) + g[i + l - 1][k - 1] -
                           g[i + l - 1][k - 1 - l] - g[i - 1][k - 1] +
                           g[i - 1][k - 1 - l]);
    }
  }
  printf("%d\n", Ans);
}
