#include <bits/stdc++.h>
using namespace std;
const int N = 500005, M = 1000000007;
int n, k, i, j, mnx, mxx, mny, mxy, vis[505][505], a[505][505], s, f[250005],
    siz[250005], vv[250005], ff[505][505], fs[505][505], ans;
char c[505][505];
void dfs(int i, int j) {
  if (c[i][j] != '.' || vis[i][j]) return;
  vis[i][j] = 1;
  ++s;
  mnx = min(mnx, i);
  mny = min(mny, j);
  mxx = max(mxx, i);
  mxy = max(mxy, j);
  dfs(i + 1, j);
  dfs(i - 1, j);
  dfs(i, j + 1);
  dfs(i, j - 1);
}
void Add(int x, int y, int p, int q, int s) {
  if (x <= p && y <= q)
    a[p + 1][q + 1] += s, a[x][q + 1] -= s, a[p + 1][y] -= s, a[x][y] += s;
}
int Find(int x) { return f[x] ? f[x] = Find(f[x]) : x; }
void uniot(int u, int v) {
  int x = Find(u), y = Find(v);
  if (x != y) {
    f[x] = y;
    siz[y] += siz[x];
  }
}
int id(int x, int y) { return (x - 1) * n + y; }
int main() {
  scanf("%d %d", &n, &k);
  for (i = 1; i <= n; ++i) scanf("%s", c[i] + 1);
  for (i = 1; i <= n; ++i)
    for (j = 1; j <= n; ++j)
      if (c[i][j] == '.' && !vis[i][j]) {
        mnx = mny = 1 << 30;
        mxx = mxy = 0;
        s = 0;
        dfs(i, j);
        Add(mxx, mxy, min(n, k + mnx - 1), min(n, k + mny - 1), s);
      }
  for (i = 1; i <= n * n; ++i) siz[i] = 1;
  for (i = 1; i <= n; ++i)
    for (j = 1; j <= n; ++j)
      if (c[i][j] == '.') {
        if (c[i - 1][j] == '.') uniot(id(i, j), id(i - 1, j));
        if (c[i][j - 1] == '.') uniot(id(i, j), id(i, j - 1));
      }
  for (i = 1; i <= n; ++i)
    for (j = 1; j <= n; ++j) {
      ff[i][j] = Find(id(i, j));
      fs[i][j] = (c[i][j] == '.' ? siz[ff[i][j]] : 0);
    }
  for (i = 1; i <= n; ++i)
    for (j = 1; j <= n; ++j)
      if (c[i][j] == 'X') Add(i, j, min(n, i + k - 1), min(n, j + k - 1), 1);
  for (i = 1; i <= n; ++i)
    for (j = 1; j <= n; ++j)
      a[i][j] = a[i][j] + a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1];
  for (i = k; i <= n; ++i)
    for (j = k; j <= n; ++j) {
      int sum = a[i][j];
      if (i != k)
        for (int l = 0; l < k; ++l)
          if (!vv[ff[i - k][j - l]]) {
            sum += fs[i - k][j - l];
            vv[ff[i - k][j - l]] = 1;
          }
      if (j != k)
        for (int l = 0; l < k; ++l)
          if (!vv[ff[i - l][j - k]]) {
            sum += fs[i - l][j - k];
            vv[ff[i - l][j - k]] = 1;
          }
      if (i != n)
        for (int l = 0; l < k; ++l)
          if (!vv[ff[i + 1][j - l]]) {
            sum += fs[i + 1][j - l];
            vv[ff[i + 1][j - l]] = 1;
          }
      if (j != n)
        for (int l = 0; l < k; ++l)
          if (!vv[ff[i - l][j + 1]]) {
            sum += fs[i - l][j + 1];
            vv[ff[i - l][j + 1]] = 1;
          }
      ans = max(ans, sum);
      if (i != k)
        for (int l = 0; l < k; ++l) vv[ff[i - k][j - l]] = 0;
      if (j != k)
        for (int l = 0; l < k; ++l) vv[ff[i - l][j - k]] = 0;
      if (i != n)
        for (int l = 0; l < k; ++l) vv[ff[i + 1][j - l]] = 0;
      if (j != n)
        for (int l = 0; l < k; ++l) vv[ff[i - l][j + 1]] = 0;
    }
  cout << ans;
}
