#include <bits/stdc++.h>
using namespace std;
const int ci[] = {1, 0, -1, 0};
const int cj[] = {0, -1, 0, 1};
int n, m;
char a[505][505];
int b[505][505];
int id[505][505], _id, counter[250005];
bool gone[505][505];
bool inside(int i, int j) { return min(i, j) >= 1 && max(i, j) <= n; }
void go(int i, int j) {
  if (gone[i][j]) return;
  gone[i][j] = true;
  id[i][j] = _id;
  ++counter[_id];
  for (int k = 0; k < 4; ++k) {
    int ii = i + ci[k];
    int jj = j + cj[k];
    if (inside(ii, jj) && a[ii][jj] == '.') go(ii, jj);
  }
}
int ncover[250005];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%s", a[i] + 1);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      b[i][j] = b[i - 1][j] + b[i][j - 1] - b[i - 1][j - 1] + (a[i][j] == 'X');
  memset(gone, false, sizeof gone);
  _id = 0;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      if (!gone[i][j] && a[i][j] == '.') {
        ++_id;
        go(i, j);
      }
  int result = 0;
  for (int i = 1; i + m - 1 <= n; ++i) {
    int white = 0;
    for (int ii = i - 1; ii <= i + m; ++ii)
      for (int jj = 1; jj <= m + 1; ++jj)
        if (!(jj == m + 1 && (ii == i - 1 || ii == i + m)) && inside(ii, jj) &&
            a[ii][jj] == '.') {
          ++ncover[id[ii][jj]];
          if (ncover[id[ii][jj]] == 1) white += counter[id[ii][jj]];
        }
    for (int j = 1; j + m - 1 <= n; ++j) {
      result =
          max(result, white + b[i + m - 1][j + m - 1] - b[i + m - 1][j - 1] -
                          b[i - 1][j + m - 1] + b[i - 1][j - 1]);
      for (int ii = i; ii < i + m; ++ii) {
        if (inside(ii, j - 1) && a[ii][j - 1] == '.') {
          --ncover[id[ii][j - 1]];
          if (ncover[id[ii][j - 1]] == 0) white -= counter[id[ii][j - 1]];
        }
        if (inside(ii, j + m + 1) && a[ii][j + m + 1] == '.') {
          ++ncover[id[ii][j + m + 1]];
          if (ncover[id[ii][j + m + 1]] == 1)
            white += counter[id[ii][j + m + 1]];
        }
      }
      if (inside(i - 1, j) && a[i - 1][j] == '.') {
        --ncover[id[i - 1][j]];
        if (ncover[id[i - 1][j]] == 0) white -= counter[id[i - 1][j]];
      }
      if (inside(i + m, j) && a[i + m][j] == '.') {
        --ncover[id[i + m][j]];
        if (ncover[id[i + m][j]] == 0) white -= counter[id[i + m][j]];
      }
      if (inside(i - 1, j + m) && a[i - 1][j + m] == '.') {
        ++ncover[id[i - 1][j + m]];
        if (ncover[id[i - 1][j + m]] == 1) white += counter[id[i - 1][j + m]];
      }
      if (inside(i + m, j + m) && a[i + m][j + m] == '.') {
        ++ncover[id[i + m][j + m]];
        if (ncover[id[i + m][j + m]] == 1) white += counter[id[i + m][j + m]];
      }
    }
    for (int ii = i - 1; ii <= i + m; ++ii)
      for (int jj = n; jj >= n - m - 1; --jj)
        if (inside(ii, jj) && a[ii][jj] == '.') ncover[id[ii][jj]] = 0;
    memset(ncover, 0, sizeof ncover);
  }
  printf("%d", result);
  return 0;
}
