#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
int n, k, grpIdx;
char board[501][501];
int grp[501][501];
int direction[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
int G[250001];
int innerG[250001];
bool visited[250001];
void dfs(int x, int y) {
  grp[x][y] = grpIdx;
  G[grpIdx]++;
  for (int i = 0; i < (int)4; i++) {
    int nx = x + direction[i][0], ny = y + direction[i][1];
    if (nx < 0 || nx >= n || ny < 0 || ny >= n || grp[nx][ny] ||
        board[nx][ny] == 'X')
      continue;
    dfs(nx, ny);
  }
}
void add(int x, int y, int a, vector<int>& idxs, int& cnt) {
  for (int l = x; l < (int)y; l++) {
    int idx = grp[a][l];
    if (idx) {
      if (!visited[idx]) visited[idx] = 1, cnt += G[idx] - innerG[idx];
      idxs.push_back(idx);
    }
  }
}
void add1(int x, int y, int a, vector<int>& idxs, int& cnt) {
  for (int l = x; l < (int)y; l++) {
    int idx = grp[l][a];
    if (idx) {
      if (!visited[idx]) visited[idx] = 1, cnt += G[idx] - innerG[idx];
      idxs.push_back(idx);
    }
  }
}
void updateInnerG(int x, int y, int idx1, int idx2) {
  for (int l = x; l < (int)y; l++) {
    int idx = grp[idx1][l];
    if (idx) innerG[idx]--;
    idx = grp[idx2][l];
    if (idx) innerG[idx]++;
  }
}
void updateInnerG1(int x, int y, int idx1, int idx2) {
  for (int l = x; l < (int)y; l++) {
    int idx = grp[l][idx1];
    if (idx) innerG[idx]--;
    idx = grp[l][idx2];
    if (idx) innerG[idx]++;
  }
}
void update(int i, int j, int K, bool b, bool b1, int& cntMax) {
  if (j == K && b)
    updateInnerG(j, j + k, i - 1, i + k - 1);
  else if (j != K) {
    if (b1)
      updateInnerG1(i, i + k, j - 1, j + k - 1);
    else
      updateInnerG1(i, i + k, j + k, j);
  }
  int cnt = 0;
  vector<int> grpIdxs;
  if (i - 1 >= 0) add(j, j + k, i - 1, grpIdxs, cnt);
  if (i + k < n) add(j, j + k, i + k, grpIdxs, cnt);
  if (j - 1 >= 0) add1(i, i + k, j - 1, grpIdxs, cnt);
  if (j + k < n) add1(i, i + k, j + k, grpIdxs, cnt);
  for (auto a : grpIdxs) visited[a] = 0;
  cntMax = max(cntMax, cnt);
}
int main() {
  memset(grp, 0, sizeof(grp));
  memset(innerG, 0, sizeof(innerG));
  memset(G, 0, sizeof(G));
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < (int)n; i++)
    for (int j = 0; j < (int)n; j++) {
      cin >> board[i][j];
    }
  grpIdx = 1;
  for (int i = 0; i < (int)n; i++)
    for (int j = 0; j < (int)n; j++) {
      if (board[i][j] == '.' && !grp[i][j]) dfs(i, j), grpIdx++;
    }
  for (int i = 0; i < (int)k; i++)
    for (int j = 0; j < (int)k; j++) {
      int gIdx = grp[i][j];
      if (gIdx) innerG[gIdx]++;
    }
  int cntMax = 0;
  for (int i = 0; i < (int)n - k + 1; i++) {
    if (i % 2) {
      for (int j = n - k; j >= 0; j--) update(i, j, n - k, 1, 0, cntMax);
    } else {
      for (int j = 0; j < (int)n - k + 1; j++) update(i, j, 0, i, 1, cntMax);
    }
  }
  cout << k * k + cntMax << "\n";
  return 0;
}
