#include <bits/stdc++.h>
using namespace std;
const int maxn = 500;
int n, ret, cnt;
char a[maxn][maxn];
int arr[maxn][maxn];
pair<int, int> par[maxn][maxn];
multiset<pair<int, int> > s;
pair<int, int> root(pair<int, int> c) {
  if (par[c.first][c.second].first < 0) return c;
  return par[c.first][c.second] = root(par[c.first][c.second]);
}
void merge(pair<int, int> A, pair<int, int> B) {
  if ((A = root(A)) == (B = root(B))) return;
  if (par[A.first][A.second].first < par[B.first][B.second].first) swap(A, B);
  par[B.first][B.second].first += par[A.first][A.second].first;
  par[A.first][A.second] = B;
}
void add(pair<int, int> A) {
  A = root(A);
  if (arr[A.first][A.second] == 0) ret += -par[A.first][A.second].first;
  arr[A.first][A.second]++;
}
void Add(pair<int, int> A) {
  int i = A.first, j = A.second;
  if (a[i][j] == 'X') ret++;
  if (a[i][j] != 'X') add({i, j});
  if (i - 1 >= 0 && a[i - 1][j] != 'X') add({i - 1, j});
  if (i + 1 < n && a[i + 1][j] != 'X') add({i + 1, j});
  if (j - 1 >= 0 && a[i][j - 1] != 'X') add({i, j - 1});
  if (j + 1 < n && a[i][j + 1] != 'X') add({i, j + 1});
}
void rem(pair<int, int> A) {
  A = root(A);
  arr[A.first][A.second]--;
  if (arr[A.first][A.second] == 0) ret -= -par[A.first][A.second].first;
}
void Rem(pair<int, int> A) {
  int i = A.first, j = A.second;
  if (a[i][j] == 'X') ret--;
  if (a[i][j] != 'X') rem({i, j});
  if (i - 1 >= 0 && a[i - 1][j] != 'X') rem({i - 1, j});
  if (i + 1 < n && a[i + 1][j] != 'X') rem({i + 1, j});
  if (j - 1 >= 0 && a[i][j - 1] != 'X') rem({i, j - 1});
  if (j + 1 < n && a[i][j + 1] != 'X') rem({i, j + 1});
}
int main() {
  ios_base::sync_with_stdio(false);
  int K;
  cin >> n >> K;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) cin >> a[i][j];
  for (int i = 0; i < maxn; i++)
    for (int j = 0; j < maxn; j++) par[i][j] = {-1, -1};
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (a[i][j] == '.') {
        if (i + 1 < n && a[i + 1][j] == '.') merge({i, j}, {i + 1, j});
        if (j + 1 < n && a[i][j + 1] == '.') merge({i, j}, {i, j + 1});
      }
  int ans = 0;
  for (int i = K - 1; i < n; i++) {
    memset(arr, 0, sizeof arr);
    ret = 0;
    for (int j = i - K + 1; j <= i; j++)
      for (int k = 0; k < K; k++) {
        Add({j, k});
      }
    ans = max(ans, ret);
    for (int j = K; j < n; j++) {
      for (int k = i - K + 1; k <= i; k++) Add({k, j});
      for (int k = i - K + 1; k <= i; k++) Rem({k, j - K});
      ans = max(ans, ret);
    }
  }
  cout << ans << endl;
  return 0;
}
