#include <bits/stdc++.h>
using namespace std;
int n, k;
int pref[503][503], col[503][503], num[250003];
int pref2[503][503];
int mox[] = {0, 0, -1, 1}, moy[] = {-1, 1, 0, 0};
int X1[250003], Y1[250003], X2[250003], Y2[250003];
bool counted[250003];
char pet[503][503];
int sum(int a, int b, int c, int d) {
  return pref[c][d] - pref[a - 1][d] - pref[c][b - 1] + pref[a - 1][b - 1];
}
void update(int a, int b, int c, int d, int val) {
  if (a > c || b > d) return;
  pref2[a][b] += val;
  pref2[c + 1][d + 1] += val;
  pref2[c + 1][b] -= val;
  pref2[a][d + 1] -= val;
}
int curr = 0, sz = 0;
void dfs(int x, int y, int c) {
  X1[c] = min(x, X1[c]);
  Y1[c] = min(y, Y1[c]);
  X2[c] = max(x, X2[c]);
  Y2[c] = max(y, Y2[c]);
  col[x][y] = c;
  sz++;
  for (int i = 0; i < 4; i++) {
    int _x = x + mox[i], _y = y + moy[i];
    if (!col[_x][_y] && pet[_x][_y] == '.') dfs(_x, _y, c);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (int i = 0; i <= 502; i++)
    for (int j = 0; j <= 502; j++) pet[i][j] = 'X';
  for (int i = 0; i <= 250000; i++) X1[i] = Y1[i] = 1e9, X2[i] = Y2[i] = -1e9;
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) cin >> pet[i][j];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      pref[i][j] = (pet[i][j] == '.');
      pref[i][j] += pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (!col[i][j] && pet[i][j] == '.') {
        sz = 0;
        dfs(i, j, ++curr);
        num[curr] = sz;
      }
    }
  }
  for (int i = 1; i <= curr; i++) {
    int x1 = max(1, X2[i] - k + 1), y1 = max(1, Y2[i] - k + 1);
    int x2 = X1[i], y2 = Y1[i];
    update(x1, y1, x2, y2, num[i]);
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      pref2[i][j] += pref2[i - 1][j] + pref2[i][j - 1] - pref2[i - 1][j - 1];
  int res = 0;
  for (int i = 1; i + k - 1 <= n; i++) {
    for (int j = 1; j + k - 1 <= n; j++) {
      vector<int> vec;
      for (int l = j; l <= j + k - 1; l++) {
        if (col[i - 1][l] && !counted[col[i - 1][l]]) {
          counted[col[i - 1][l]] = 1;
          vec.push_back(col[i - 1][l]);
        }
        if (col[i + k][l] && !counted[col[i + k][l]]) {
          counted[col[i + k][l]] = 1;
          vec.push_back(col[i + k][l]);
        }
      }
      for (int l = i; l <= i + k - 1; l++) {
        if (col[l][j - 1] && !counted[col[l][j - 1]]) {
          counted[col[l][j - 1]] = 1;
          vec.push_back(col[l][j - 1]);
        }
        if (col[l][j + k] && !counted[col[l][j + k]]) {
          counted[col[l][j + k]] = 1;
          vec.push_back(col[l][j + k]);
        }
      }
      int cnt = 0;
      for (auto l : vec) {
        cnt += num[l];
        counted[l] = 0;
      }
      cnt += k * k - sum(i, j, i + k - 1, j + k - 1);
      cnt += pref2[i][j];
      res = max(res, cnt);
    }
  }
  cout << res << "\n";
}
