#include <bits/stdc++.h>
using namespace std;
template <class T, class L>
bool smax(T &x, L y) {
  return x < y ? (x = y, 1) : 0;
}
template <class T, class L>
bool smin(T &x, L y) {
  return y < x ? (x = y, 1) : 0;
}
const int maxn = 5e2 + 17;
int n, m, k, ps[maxn][maxn], comp[maxn][maxn], sz[maxn * maxn], c_cnt,
    xs[] = {-1, 1, 0, 0}, ys[] = {0, 0, -1, 1};
int last[maxn * maxn], cur;
char c[maxn][maxn];
void dfs(int x, int y) {
  if (x < 0 || y < 0 || x >= n || y >= m || c[x][y] == 'X' || ~comp[x][y])
    return;
  comp[x][y] = c_cnt;
  sz[c_cnt]++;
  for (int i = 0; i < 4; i++) dfs(x + xs[i], y + ys[i]);
}
void upd(int x, int y, bool ad) {
  if (x < 0 || y < 0 || x >= n || y >= m || c[x][y] == 'X') return;
  if (ad) {
    if (last[comp[x][y]] == 0) cur += sz[comp[x][y]];
    last[comp[x][y]]++;
  } else if (--last[comp[x][y]] == 0)
    cur -= sz[comp[x][y]];
}
int sum(int x, int y) {
  return ps[x + k - 1][y + k - 1] - (x ? ps[x - 1][y + k - 1] : 0) -
         (y ? ps[x + k - 1][y - 1] : 0) + (x && y ? ps[x - 1][y - 1] : 0);
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> k;
  m = n;
  for (int i = 0; i < n; i++) cin >> c[i];
  memset(comp, -1, sizeof comp);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (c[i][j] == '.' && comp[i][j] == -1) dfs(i, j), c_cnt++;
      ps[i][j] = (c[i][j] == 'X') + (i ? ps[i - 1][j] : 0) +
                 (j ? ps[i][j - 1] : 0) - (i && j ? ps[i - 1][j - 1] : 0);
    }
  int ans = 0;
  for (int r = 0; r <= n - k; r++) {
    memset(last, 0, sizeof last), cur = 0;
    for (int x = r - 1; x <= r + k; x++)
      for (int y = 0; y < k; y++) upd(x, y, 1);
    for (int x = r; x < r + k; x++) upd(x, k, 1);
    for (int c = 0; c <= m - k; c++) {
      smax(ans, cur + sum(r, c));
      for (int x = r; x < r + k; x++) upd(x, c - 1, 0);
      upd(r - 1, c, 0), upd(r + k, c, 0);
      for (int x = r; x < r + k; x++) upd(x, c + k + 1, 1);
      upd(r - 1, c + k, 1), upd(r + k, c + k, 1);
    }
  }
  cout << ans << '\n';
  return 0;
}
