#include <bits/stdc++.h>
using namespace std;
char s[505][505];
int g[505][505];
int gs[250005];
int f[250005];
int ps[505][505];
void dfs(int x, int y, int l) {
  if (g[x][y]) return;
  if (s[x][y] == 'X') return;
  gs[l]++;
  g[x][y] = l;
  if (s[x - 1][y] == '.') dfs(x - 1, y, l);
  if (s[x + 1][y] == '.') dfs(x + 1, y, l);
  if (s[x][y + 1] == '.') dfs(x, y + 1, l);
  if (s[x][y - 1] == '.') dfs(x, y - 1, l);
}
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s[i] + 1);
  }
  int l = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      ps[i][j] =
          ps[i - 1][j] + ps[i][j - 1] - ps[i - 1][j - 1] + (s[i][j] == 'X');
      if (g[i][j]) continue;
      if (s[i][j] == 'X') continue;
      dfs(i, j, l);
      l++;
    }
  }
  int ans = 0;
  for (int i = 1; i + k - 1 <= n; i++) {
    memset(f, 0, sizeof f);
    int sum = 0;
    for (int l = 0; l <= k; l++) {
      for (int j = i; j < i + k; j++) {
        sum += (f[g[j][l]]++ == 0 ? gs[g[j][l]] : 0);
      }
      if (l < k) {
        sum += (f[g[i - 1][l]]++ == 0 ? gs[g[i - 1][l]] : 0);
        sum += (f[g[i + k][l]]++ == 0 ? gs[g[i + k][l]] : 0);
      }
    }
    for (int l = k; l <= n; l++) {
      for (int j = i; j < i + k; j++) {
        sum += (f[g[j][l + 1]]++ == 0 ? gs[g[j][l + 1]] : 0);
        sum -= (--f[g[j][l - k - 1]] == 0 ? gs[g[j][l - k - 1]] : 0);
      }
      sum += (f[g[i - 1][l]]++ == 0 ? gs[g[i - 1][l]] : 0);
      sum += (f[g[i + k][l]]++ == 0 ? gs[g[i + k][l]] : 0);
      sum -= (--f[g[i - 1][l - k]] == 0 ? gs[g[i - 1][l - k]] : 0);
      sum -= (--f[g[i + k][l - k]] == 0 ? gs[g[i + k][l - k]] : 0);
      ans = max(ans, sum + ps[i + k - 1][l] - ps[i + k - 1][l - k] -
                         ps[i - 1][l] + ps[i - 1][l - k]);
    }
  }
  printf("%d\n", ans);
  return 0;
}
