#include <bits/stdc++.h>
using namespace std;
template <typename T>
T qmin(const T a, const T b) {
  return a < b ? a : b;
}
template <typename T>
T qmax(const T a, const T b) {
  return a > b ? a : b;
}
template <typename T>
void getmin(T &a, const T b) {
  if (a > b) a = b;
}
template <typename T>
void getmax(T &a, const T b) {
  if (a < b) a = b;
}
void fileio(string s) {
  if (s.empty()) return;
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}
const int inf = 1e9 + 7;
const long long linf = 1e16 + 7;
const int N = 505;
const int go[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
char a[N][N];
int id[N][N], block[N][N], cnt, n, k;
bool used[N * N], inuse[N * N];
int num[N * N], uu[N * N], ud[N * N], ul[N * N], ur[N * N], cur, ans;
void dfs(int x, int y, int p) {
  id[x][y] = p;
  ++num[p];
  getmax(ur[p], y);
  getmax(ud[p], x);
  getmin(uu[p], x);
  getmin(ul[p], y);
  for (int c = 0; c < 4; ++c) {
    int nx = x + go[c][0], ny = y + go[c][1];
    if (nx < 1 || nx > n || ny < 1 || ny > n || a[nx][ny] == 'X' || id[nx][ny])
      continue;
    dfs(nx, ny, p);
  }
}
bool ins(int p, int x1, int x2, int y1, int y2) {
  return ul[p] >= y1 && ur[p] <= y2 && uu[p] >= x1 && ud[p] <= x2;
}
int main() {
  scanf("%d%d", &n, &k);
  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++) {
      if (a[i][j] == '.' && !id[i][j]) {
        ++cnt;
        uu[cnt] = ul[cnt] = inf;
        ud[cnt] = ur[cnt] = 0;
        dfs(i, j, cnt);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      block[i][j] = block[i - 1][j] + block[i][j - 1] - block[i - 1][j - 1] +
                    (a[i][j] == 'X' ? 1 : 0);
    }
  }
  for (int i = 1; i + k - 1 <= n; i++) {
    memset(used, false, sizeof(*used) * (cnt + 1));
    memset(inuse, false, sizeof(*inuse) * (cnt + 1));
    cur = 0;
    for (int x = i; x < i + k; ++x) {
      for (int y = 1; y <= k; ++y) {
        int p = id[x][y];
        if (!p || used[p] || !ins(p, i, i + k - 1, 1, k)) continue;
        used[p] = true;
        cur += num[p];
      }
    }
    for (int j = 1; j + k - 1 <= n; ++j) {
      int x1 = i, y1 = j, x2 = i + k - 1, y2 = j + k - 1;
      for (int t = x1; t <= x2; ++t) {
        int p = id[t][y1 - 1];
        if (p && !inuse[p]) cur += num[p], inuse[p] = true;
        p = id[t][y2 + 1];
        if (p && !inuse[p]) cur += num[p], inuse[p] = true;
      }
      for (int t = y1; t <= y2; ++t) {
        int p = id[x1 - 1][t];
        if (p && !inuse[p]) cur += num[p], inuse[p] = true;
        p = id[x2 + 1][t];
        if (p && !inuse[p]) cur += num[p], inuse[p] = true;
      }
      getmax(ans, cur + block[x2][y2] - block[x1 - 1][y2] - block[x2][y1 - 1] +
                      block[x1 - 1][y1 - 1]);
      for (int t = x1; t <= x2; ++t) {
        int p = id[t][y1 - 1];
        if (inuse[p]) cur -= num[p], inuse[p] = false;
        p = id[t][y2 + 1];
        if (inuse[p]) cur -= num[p], inuse[p] = false;
      }
      for (int t = y1; t <= y2; ++t) {
        int p = id[x1 - 1][t];
        if (inuse[p]) cur -= num[p], inuse[p] = false;
        p = id[x2 + 1][t];
        if (inuse[p]) cur -= num[p], inuse[p] = false;
      }
      for (int t = x1; t <= x2; ++t) {
        int p = id[t][y1];
        if (used[p] && !ins(p, x1, x2, y1 + 1, y2 + 1))
          cur -= num[p], used[p] = false;
        p = id[t][y2 + 1];
        if (p && !used[p] && ins(p, x1, x2, y1 + 1, y2 + 1))
          cur += num[p], used[p] = true;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
