#include <bits/stdc++.h>
const int MAX_N = 505 * 505;
const double eps = 1e-6;
const int inf = (int)1e9 + 123;
using namespace std;
int pr[MAX_N], sz[MAX_N], h[MAX_N];
int Parent(int a) {
  if (a == pr[a]) return a;
  return pr[a] = Parent(pr[a]);
}
void Union(int a, int b) {
  a = Parent(a), b = Parent(b);
  if (a == b) return;
  if (h[a] < h[b]) swap(a, b);
  pr[b] = a;
  sz[a] += sz[b];
  h[a] += (h[a] == h[b]);
}
int cnt[MAX_N];
int all;
void add(int x) {
  if (!cnt[x]) all += sz[x];
  cnt[x]++;
}
void del(int x) {
  cnt[x]--;
  if (!cnt[x]) all -= sz[x];
}
char a[505][505];
int n, k;
int sum[505][505];
int moves[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
int id(int x, int y) { return (x - 1) * n + y - 1; }
int get_sum(int x, int y, int x2, int y2) {
  return sum[x2][y2] - sum[x - 1][y2] - sum[x2][y - 1] + sum[x - 1][y - 1];
}
void Add(int x, int y) {
  for (int i = 0; i < n * n; i++) cnt[i] = 0;
  all = 0;
  for (int i = x; i <= x + k - 1; i++)
    for (int j = y; j <= y + k - 1; j++)
      if (a[i][j] == '.') add(Parent(id(i, j)));
  if (x > 1)
    for (int j = y; j <= y + k - 1; j++)
      if (a[x - 1][j] == '.') add(Parent(id(x - 1, j)));
  if (x + k <= n)
    for (int j = y; j <= y + k - 1; j++)
      if (a[x + k][j] == '.') add(Parent(id(x + k, j)));
  if (y + k <= n)
    for (int i = x; i <= x + k - 1; i++)
      if (a[i][y + k] == '.') add(Parent(id(i, y + k)));
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      cin >> a[i][j];
      sum[i][j] =
          sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + (a[i][j] == 'X');
    }
  for (int i = 0; i < n * n; i++) pr[i] = i, sz[i] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      for (int k = 0; k < 4; k++) {
        int ni = i + moves[k][0], nj = j + moves[k][1];
        if (ni > 0 && ni <= n && nj > 0 && nj <= n && a[i][j] == '.' &&
            a[ni][nj] == '.')
          Union(id(i, j), id(ni, nj));
      }
    }
  int ans = 0;
  for (int i = 1; i + k - 1 <= n; i++) {
    Add(i, 1);
    for (int j = 1; j + k - 1 <= n; j++) {
      ans = max(ans, all + get_sum(i, j, i + k - 1, j + k - 1));
      if (j > 1)
        for (int i2 = i; i2 <= i + k - 1; i2++)
          if (a[i2][j - 1] == '.') del(Parent(id(i2, j - 1)));
      if (i > 1 && a[i - 1][j] == '.') del(Parent(id(i - 1, j)));
      if (i + k <= n && a[i + k][j] == '.') del(Parent(id(i + k, j)));
      if (i > 1 && a[i - 1][j + k] == '.') add(Parent(id(i - 1, j + k)));
      if (i + k <= n && a[i + k][j + k] == '.') add(Parent(id(i + k, j + k)));
      if (j + k + 1 <= n)
        for (int i2 = i; i2 <= i + k - 1; i2++)
          if (a[i2][j + k + 1] == '.') add(Parent(id(i2, j + k + 1)));
    }
  }
  cout << ans;
  return 0;
}
