#include <bits/stdc++.h>
using namespace std;
string s[505];
int n, a[505 * 505] = {0}, v[505 * 505] = {0}, p[505 * 505];
bool b[505 * 505] = {0};
int findPar(int u) {
  if (p[u] == -1) return p[u] = u;
  if (u == p[u]) return u;
  return p[u] = findPar(p[u]);
}
void unionSet(int u, int v) {
  int pu = findPar(u);
  int pv = findPar(v);
  p[pv] = pu;
}
void reset(int bx, int ex, int by, int ey) {
  int i, j;
  for (i = bx; i <= ex; i++) {
    for (j = by; j <= ey; j++) b[findPar(i * n + j)] = 0;
  }
}
int get_sum(int bx, int ex, int by, int ey) {
  int i, j, ret = 0, u;
  for (i = bx; i <= ex; i++) {
    for (j = by; j <= ey; j++) {
      if (s[i][j] == 'X') continue;
      u = findPar(i * n + j);
      if (v[u] == 0 && b[u] == 0) ret += a[u];
      b[u] = 1;
    }
  }
  return ret;
}
int main() {
  std::ios_base::sync_with_stdio(0);
  int cases, caseno = 0, i, j, k, t, u, mx, sum, temp;
  cin >> n >> k;
  for (i = 0; i <= n - 1; i++) cin >> s[i];
  memset(p, -1, sizeof(p));
  for (i = 0; i <= n - 1; i++) {
    for (j = 0; j <= n - 1; j++) {
      if (s[i][j] == '.') {
        if (i > 0 && s[i - 1][j] == '.') unionSet(i * n + j, (i - 1) * n + j);
        if (j > 0 && s[i][j - 1] == '.') unionSet(i * n + j, i * n + (j - 1));
      }
    }
  }
  for (i = 0; i <= n - 1; i++) {
    for (j = 0; j <= n - 1; j++) {
      temp = findPar(i * n + j);
    }
  }
  for (i = 0; i <= n - 1; i++) {
    for (j = 0; j <= n - 1; j++) a[findPar(i * n + j)]++;
  }
  mx = 0;
  for (i = 0; i <= n - k; i++) {
    sum = 0;
    memset(v, 0, sizeof(v));
    for (t = i; t <= i + k - 1; t++) {
      for (j = 0; j <= k - 1; j++) {
        u = findPar(t * n + j);
        v[u]++;
        if (v[u] == 1) sum += a[u];
      }
    }
    for (j = 0; j <= n - k; j++) {
      temp = 0;
      if (j > 0) {
        for (t = i; t <= i + k - 1; t++) {
          u = findPar(t * n + (j - 1));
          v[u]--;
          if (v[u] == 0) sum -= a[u];
        }
        for (t = i; t <= i + k - 1; t++) {
          u = findPar(t * n + (j + k - 1));
          v[u]++;
          if (v[u] == 1) sum += a[u];
        }
      }
      memset(b, 0, sizeof(b));
      if (i > 0) temp += get_sum(i - 1, i - 1, j, j + k - 1);
      if (i + k < n) temp += get_sum(i + k, i + k, j, j + k - 1);
      if (j > 0) temp += get_sum(i, i + k - 1, j - 1, j - 1);
      if (j + k < n) temp += get_sum(i, i + k - 1, j + k, j + k);
      mx = max(mx, sum + temp);
    }
  }
  cout << mx << '\n';
  return 0;
}
