#include <bits/stdc++.h>
using namespace std;
const long long N = 510;
string s[N];
long long pref[N][N];
long long comp[N][N];
long long sz[N * N];
long long xl[N * N], xr[N * N], yl[N * N], yr[N * N];
bool in[N * N];
bool brd[N * N];
void dfs(long long first, long long second, long long c) {
  if (comp[first][second] || s[first][second] == 'X') return;
  comp[first][second] = c;
  sz[c]++;
  xl[c] = min(xl[c], first);
  xr[c] = max(xr[c], first);
  yl[c] = min(yl[c], second);
  yr[c] = max(yr[c], second);
  dfs(first + 1, second, c);
  dfs(first - 1, second, c);
  dfs(first, second + 1, c);
  dfs(first, second - 1, c);
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) cin >> s[i], s[i] = "X" + s[i] + "X";
  s[0] = s[n + 1] = string(n + 2, 'X');
  long long cnt = 0;
  for (long long first = 1; first <= n; first++)
    for (long long second = 1; second <= n; second++) {
      if (s[first][second] == 'X') pref[first][second] = 1;
      pref[first][second] += pref[first - 1][second] + pref[first][second - 1] -
                             pref[first - 1][second - 1];
      if (s[first][second] == '.') {
        cnt++;
        xl[cnt] = yl[cnt] = 1e9;
        xr[cnt] = yr[cnt] = -1e9;
        dfs(first, second, cnt);
      }
    }
  long long ans = 0;
  for (long long first = 1; first + k - 1 <= n; first++) {
    long long in_sum = 0;
    for (long long c = 1; c <= cnt; c++)
      if (first <= xl[c] && xr[c] <= first + k - 1 && 1 <= yl[c] &&
          yr[c] <= 1 + k - 1)
        in[c] = true, in_sum += sz[c];
      else
        in[c] = false;
    long long second = 0;
    while (second <= n - 1) {
      if (second)
        for (long long i = first; i <= first + k - 1; i++) {
          long long c = comp[i][second + k - 1 + 1];
          second++;
          {
            bool need = (first <= xl[c] && xr[c] <= first + k - 1 &&
                         second <= yl[c] && yr[c] <= second + k - 1);
            bool now = in[c];
            if (need && !now) in[c] = true, in_sum += sz[c];
            if (!need && now) in[c] = false, in_sum -= sz[c];
          }
          second--;
        }
      second++;
      for (long long i = first; i <= first + k - 1; i++) {
        long long c = comp[i][second - 1];
        {
          bool need = (first <= xl[c] && xr[c] <= first + k - 1 &&
                       second <= yl[c] && yr[c] <= second + k - 1);
          bool now = in[c];
          if (need && !now) in[c] = true, in_sum += sz[c];
          if (!need && now) in[c] = false, in_sum -= sz[c];
        }
      }
      long long res = in_sum + pref[first + k - 1][second + k - 1] -
                      pref[first - 1][second + k - 1] -
                      pref[first + k - 1][second - 1] +
                      pref[first - 1][second - 1];
      for (long long i = first; i <= first + k - 1; i++) {
        if (!brd[comp[i][second - 1]])
          res += sz[comp[i][second - 1]], brd[comp[i][second - 1]] = true;
        if (!brd[comp[i][second + k - 1 + 1]])
          res += sz[comp[i][second + k - 1 + 1]],
              brd[comp[i][second + k - 1 + 1]] = true;
      }
      for (long long j = second; j <= second + k - 1; j++) {
        if (!brd[comp[first - 1][j]])
          res += sz[comp[first - 1][j]], brd[comp[first - 1][j]] = true;
        if (!brd[comp[first + k - 1 + 1][j]])
          res += sz[comp[first + k - 1 + 1][j]],
              brd[comp[first + k - 1 + 1][j]] = true;
      }
      ans = max(ans, res);
      for (long long i = first; i <= first + k - 1; i++) {
        brd[comp[i][second - 1]] = false;
        brd[comp[i][second + k - 1 + 1]] = false;
      }
      for (long long j = second; j <= second + k - 1; j++) {
        brd[comp[first - 1][j]] = false;
        brd[comp[first + k - 1 + 1][j]] = false;
      }
    }
  }
  cout << ans;
}
