#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
int n, k;
char g[510][510];
int mark[510][510];
int sum[510][510];
pair<int, int> mi[510 * 510], ma[510 * 510];
int cnt[510 * 510];
int up[510];
vector<int> ev[510];
int mark2[510 * 510], passo;
int di[] = {1, 0, -1, 0};
int dj[] = {0, 1, 0, -1};
inline bool can(int i, int j) { return i >= 0 && i < n && j >= 0 && j < n; }
int dfs(int i, int j, int c, int &mi_i, int &ma_i, int &mi_j, int &ma_j) {
  mark[i][j] = c;
  mi_i = min(mi_i, i);
  ma_i = max(ma_i, i);
  mi_j = min(mi_j, j);
  ma_j = max(ma_j, j);
  int ret = 1;
  for (int(k) = (0); (k) < (4); ++(k)) {
    int ni = i + di[k];
    int nj = j + dj[k];
    if (can(ni, nj) && g[ni][nj] == '.' && !mark[ni][nj]) {
      ret += dfs(ni, nj, c, mi_i, ma_i, mi_j, ma_j);
    }
  }
  return ret;
}
inline int get(int i, int j) {
  if (can(i, j) && mark[i][j] && mark2[mark[i][j]] != passo) {
    mark2[mark[i][j]] = passo;
    return cnt[mark[i][j]];
  }
  return 0;
}
int main() {
  memset((mark2), (0), sizeof(mark2));
  passo = 0;
  memset((mark), (0), sizeof(mark));
  memset((up), (0), sizeof(up));
  memset((sum), (0), sizeof(sum));
  scanf("%d%d", &n, &k);
  for (int(i) = (0); (i) < (n); ++(i)) scanf("%s", g[i]);
  int c = 1;
  for (int(i) = (0); (i) < (n); ++(i))
    for (int(j) = (0); (j) < (n); ++(j)) {
      if (!mark[i][j] && g[i][j] == '.') {
        mi[c] = pair<int, int>(i, j);
        ma[c] = pair<int, int>(i, j);
        cnt[c] =
            dfs(i, j, c, mi[c].first, ma[c].first, mi[c].second, ma[c].second);
        if (ma[c].first - mi[c].first <= k &&
            ma[c].second - mi[c].second <= k) {
          ev[max(ma[c].first - k + 1, 0)].push_back(c);
          ev[mi[c].first + 1].push_back(-c);
        }
        c++;
      }
      sum[i + 1][j + 1] =
          sum[i + 1][j] + sum[i][j + 1] - sum[i][j] + (g[i][j] == 'X');
    }
  multiset<pair<int, int> > ms;
  int ans = 0;
  for (int(i) = (0); (i) < (n - k + 1); ++(i)) {
    for (auto t : ev[i]) {
      int sign = (t > 0) ? 1 : -1;
      t = abs(t);
      up[max(ma[t].second - k + 1, 0)] += sign * cnt[t];
      up[mi[t].second + 1] -= sign * cnt[t];
    }
    int tup = 0;
    for (int(j) = (0); (j) < (n - k + 1); ++(j)) {
      tup += up[j];
      int tmp =
          tup + sum[i + k][j + k] - sum[i + k][j] - sum[i][j + k] + sum[i][j];
      passo++;
      for (int(l) = (0); (l) < (k); ++(l)) {
        tmp = tmp + get(i + l, j - 1) + get(i + l, j + k) + get(i - 1, j + l) +
              get(i + k, j + l);
      }
      ans = max(ans, tmp);
    }
  }
  printf("%d\n", ans);
  return 0;
}
