#include <bits/stdc++.h>
using namespace std;
int CC[500][500] = {0};
int CCSize[500 * 500 + 1] = {0};
char grid[500][501];
int N, K;
int curCCSize = 0;
int CCCount;
void dfs(int ati, int atj) {
  if (!(0 <= ati && ati < N && 0 <= atj && atj < N)) return;
  if (CC[ati][atj] != 0 || grid[ati][atj] == 'X') return;
  CC[ati][atj] = CCCount;
  curCCSize++;
  dfs(ati + 1, atj);
  dfs(ati - 1, atj);
  dfs(ati, atj + 1);
  dfs(ati, atj - 1);
}
int checkBoundary(int ii, int jj, int* curFreq) {
  int i, j;
  int totalTouchCount = 0;
  bool included[500 * 500 + 1] = {0};
  i = ii - 1;
  if (i >= 0)
    for (j = jj; j <= jj + K - 1; j++) {
      if (!included[CC[i][j]] && grid[i][j] != 'X') {
        included[CC[i][j]] = true;
        totalTouchCount += CCSize[CC[i][j]];
        totalTouchCount -= curFreq[CC[i][j]];
      }
    }
  i = ii + K;
  if (i < N)
    for (j = jj; j <= jj + K - 1; j++) {
      if (!included[CC[i][j]] && grid[i][j] != 'X') {
        included[CC[i][j]] = true;
        totalTouchCount += CCSize[CC[i][j]];
        totalTouchCount -= curFreq[CC[i][j]];
      }
    }
  j = jj - 1;
  if (j >= 0)
    for (i = ii; i <= ii + K - 1; i++) {
      if (!included[CC[i][j]] && grid[i][j] != 'X') {
        included[CC[i][j]] = true;
        totalTouchCount += CCSize[CC[i][j]];
        totalTouchCount -= curFreq[CC[i][j]];
      }
    }
  j = jj + K;
  if (j < N)
    for (i = ii; i <= ii + K - 1; i++) {
      if (!included[CC[i][j]] && grid[i][j] != 'X') {
        included[CC[i][j]] = true;
        totalTouchCount += CCSize[CC[i][j]];
        totalTouchCount -= curFreq[CC[i][j]];
      }
    }
  return totalTouchCount;
}
int main() {
  int i, j;
  cin >> N >> K;
  for (i = 0; i < N; i++) {
    cin >> grid[i];
  }
  CCCount = 0;
  for (i = 0; i < N; i++) {
    for (j = 0; j < N; j++) {
      if (CC[i][j] == 0 && grid[i][j] != 'X') {
        CCCount++;
        curCCSize = 0;
        dfs(i, j);
        CCSize[CCCount] = curCCSize;
      }
    }
  }
  int ans = 0;
  int ii;
  for (ii = 0; ii <= N - K; ii++) {
    int curFreq[500 * 500 + 1] = {0};
    for (j = 0; j < K; j++) {
      for (i = ii; i < ii + K; i++) {
        curFreq[CC[i][j]]++;
      }
    }
    ans = max(ans, K * K + checkBoundary(ii, 0, curFreq));
    for (j = 1; j <= N - K; j++) {
      for (i = ii; i < ii + K; i++) {
        curFreq[CC[i][j - 1]]--;
        assert(curFreq[CC[i][j - 1]] >= 0);
        curFreq[CC[i][j + K - 1]]++;
      }
      ans = max(ans, K * K + checkBoundary(ii, j, curFreq));
    }
  }
  cout << ans;
  return 0;
}
