#include <bits/stdc++.h>
using namespace std;
int area[505][505];
int cmp[505][505];
int gox[4] = {0, 1, 0, -1};
int goy[4] = {1, 0, -1, 0};
int n, k;
void dfs(int x, int y, int cnum) {
  if (area[x][y] == 0) return;
  cmp[x][y] = cnum;
  for (int j = 0; j < 4; j++) {
    int nx = x + gox[j], ny = y + goy[j];
    if (nx >= 0 && ny >= 0 && nx < n && ny < n && cmp[nx][ny] == -1)
      dfs(nx, ny, cnum);
  }
}
int all[505 * 505], inside[505 * 505];
int F;
int used[505 * 505];
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      char u;
      cin >> u;
      if (u == 'X')
        area[i][j] = 0;
      else
        area[i][j] = 1;
    }
  int ccnt = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) cmp[i][j] = -1;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (area[i][j] == 1 && cmp[i][j] == -1) dfs(i, j, ccnt++);
  for (int i = 0; i < ccnt; i++) all[i] = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (cmp[i][j] != -1) all[cmp[i][j]]++;
  int big = 0;
  for (int i = 0; i < ccnt; i++) big = max(big, all[i]);
  for (int i = 0; i < ccnt; i++) used[i] = 0;
  for (int j = 0; j + k <= n; j++) {
    for (int i = 0; i < ccnt; i++) inside[i] = 0;
    for (int x = 0; x < k; x++)
      for (int y = 0; y < k; y++)
        if (cmp[x + j][y] != -1) inside[cmp[x + j][y]]++;
    for (int i = 0; i + k <= n; i++) {
      int add = 0;
      F++;
      for (int t = 0; t <= 1; t++) {
        for (int c = 0; c < k; c++) {
          int row[2] = {j + t * (k + 1) - 1, j + c};
          int col[2] = {i + c, i + t * (k + 1) - 1};
          for (int g = 0; g < 2; g++)
            if (row[g] >= 0 && row[g] < n && col[g] >= 0 && col[g] < n &&
                cmp[row[g]][col[g]] != -1 && used[cmp[row[g]][col[g]]] != F) {
              add += all[cmp[row[g]][col[g]]] - inside[cmp[row[g]][col[g]]];
              used[cmp[row[g]][col[g]]] = F;
            }
        }
      }
      big = max(big, k * k + add);
      for (int t = 0; t < k; t++) {
        if (cmp[j + t][i] != -1) inside[cmp[j + t][i]]--;
        if (cmp[j + t][i + k] != -1) inside[cmp[j + t][i + k]]++;
      }
    }
  }
  cout << big << endl;
  return 0;
}
