#include <bits/stdc++.h>
using namespace std;
int n, k, grid[505][505], vis[505][505] = {}, comp[505][505] = {};
char x;
int comps = 0, sz[505 * 505] = {}, cnt[505 * 505] = {}, ans = 0;
int main() {
  int di[4] = {0, 1, 0, -1}, dj[4] = {1, 0, -1, 0};
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  for (int i = 0, _i = (n); i < _i; ++i)
    for (int j = 0, _j = (n); j < _j; ++j) {
      cin >> x;
      grid[i][j] = x == '.';
    }
  for (int i = 0, _i = (n); i < _i; ++i) {
    for (int j = 0, _j = (n); j < _j; ++j) {
      if (!vis[i][j] && grid[i][j]) {
        queue<pair<int, int> > q({make_pair(i, j)});
        comps++;
        while (!q.empty()) {
          int r = q.front().first, c = q.front().second;
          q.pop();
          if (vis[r][c]) continue;
          comp[r][c] = comps;
          sz[comps]++;
          vis[r][c] = 1;
          for (int k = 0, _k = (4); k < _k; ++k) {
            int nr = r + di[k], nc = c + dj[k];
            if ((nr >= 0 && nc >= 0 && nr < n && nc < n) && grid[nr][nc] &&
                !vis[nr][nc]) {
              q.push(make_pair(nr, nc));
            }
          }
        }
      }
    }
  }
  int dp[505][505] = {};
  for (int i = (n), _i = (0); --i >= _i;) {
    for (int j = (n), _j = (0); --j >= _j;) {
      dp[i][j] = dp[i][j + 1] + dp[i + 1][j] - dp[i + 1][j + 1] + !grid[i][j];
    }
  }
  int cursz = 0;
  for (int i = 0, _i = (k + 1); i < _i; ++i) {
    for (int j = 0, _j = (k + 1); j < _j; ++j) {
      if (i == k && j == k) continue;
      cnt[comp[i][j]] += 1;
      if (cnt[comp[i][j]] == (1 == 1)) cursz += 1 * sz[comp[i][j]];
      ;
    }
  }
  ans = max(cursz + (dp[0][0] + dp[0 + k][0 + k] - dp[0][0 + k] - dp[0 + k][0]),
            ans);
  int r = 0, c = 0, dir = 1;
  while (1) {
    int nc = c + dir;
    if (nc > n - k || nc < 0) {
      if (r == n - k) break;
      if (r > 0) {
        for (int i = (c), _i = (c + k); i < _i; ++i) {
          cnt[comp[r - 1][i]] += -1;
          if (cnt[comp[r - 1][i]] == (-1 == 1))
            cursz += -1 * sz[comp[r - 1][i]];
          ;
        }
      }
      if (r + k + 1 < n) {
        for (int i = (c), _i = (c + k); i < _i; ++i) {
          cnt[comp[r + k + 1][i]] += 1;
          if (cnt[comp[r + k + 1][i]] == (1 == 1))
            cursz += 1 * sz[comp[r + k + 1][i]];
          ;
        }
      }
      if ((r >= 0 && c - 1 >= 0 && r < n && c - 1 < n)) {
        cnt[comp[r][c - 1]] += -1;
        if (cnt[comp[r][c - 1]] == (-1 == 1)) cursz += -1 * sz[comp[r][c - 1]];
        ;
      }
      if ((r >= 0 && c + k >= 0 && r < n && c + k < n)) {
        cnt[comp[r][c + k]] += -1;
        if (cnt[comp[r][c + k]] == (-1 == 1)) cursz += -1 * sz[comp[r][c + k]];
        ;
      }
      if ((r + k >= 0 && c - 1 >= 0 && r + k < n && c - 1 < n)) {
        cnt[comp[r + k][c - 1]] += 1;
        if (cnt[comp[r + k][c - 1]] == (1 == 1))
          cursz += 1 * sz[comp[r + k][c - 1]];
        ;
      }
      if ((r + k >= 0 && c + k >= 0 && r + k < n && c + k < n)) {
        cnt[comp[r + k][c + k]] += 1;
        if (cnt[comp[r + k][c + k]] == (1 == 1))
          cursz += 1 * sz[comp[r + k][c + k]];
        ;
      }
      dir *= -1;
      r++;
      ans = max(
          cursz + (dp[r][c] + dp[r + k][c + k] - dp[r][c + k] - dp[r + k][c]),
          ans);
      continue;
    }
    int cc = (dir == 1) ? c - 1 : c + k;
    if ((r >= 0 && cc >= 0 && r < n && cc < n)) {
      for (int i = (r), _i = (r + k); i < _i; ++i) {
        cnt[comp[i][cc]] += -1;
        if (cnt[comp[i][cc]] == (-1 == 1)) cursz += -1 * sz[comp[i][cc]];
        ;
      }
    }
    cc = (dir == 1) ? c + k + 1 : c - 2;
    if ((r >= 0 && cc >= 0 && r < n && cc < n)) {
      for (int i = (r), _i = (r + k); i < _i; ++i) {
        cnt[comp[i][cc]] += 1;
        if (cnt[comp[i][cc]] == (1 == 1)) cursz += 1 * sz[comp[i][cc]];
        ;
      }
    }
    if (dir == -1) c--;
    if ((r - 1 >= 0 && c >= 0 && r - 1 < n && c < n)) {
      cnt[comp[r - 1][c]] += -dir;
      if (cnt[comp[r - 1][c]] == (-dir == 1))
        cursz += -dir * sz[comp[r - 1][c]];
      ;
    }
    if ((r + k >= 0 && c >= 0 && r + k < n && c < n)) {
      cnt[comp[r + k][c]] += -dir;
      if (cnt[comp[r + k][c]] == (-dir == 1))
        cursz += -dir * sz[comp[r + k][c]];
      ;
    }
    if ((r - 1 >= 0 && c + k >= 0 && r - 1 < n && c + k < n)) {
      cnt[comp[r - 1][c + k]] += dir;
      if (cnt[comp[r - 1][c + k]] == (dir == 1))
        cursz += dir * sz[comp[r - 1][c + k]];
      ;
    }
    if ((r + k >= 0 && c + k >= 0 && r + k < n && c + k < n)) {
      cnt[comp[r + k][c + k]] += dir;
      if (cnt[comp[r + k][c + k]] == (dir == 1))
        cursz += dir * sz[comp[r + k][c + k]];
      ;
    }
    if (dir == -1) c++;
    c = nc;
    ans =
        max(cursz + (dp[r][c] + dp[r + k][c + k] - dp[r][c + k] - dp[r + k][c]),
            ans);
  }
  cout << ans;
}
