#include <bits/stdc++.h>
using namespace std;
template <class TH>
void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << " = " << h << endl;
}
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << " = " << h << ", ";
  _dbg(sdbg + 1, a...);
}
const int maxn = (1e6) + 7;
const int maxk = 20;
const int inf = (1e9) + 7;
const long long LLinf = (1e18) + 7;
const long double eps = 1e-9;
const long long mod = 1e9 + 7;
vector<pair<int, int> > mov = {{1, 0}, {-1, 0}, {0, -1}, {0, 1}};
int F[maxn];
int r[maxn];
int stan[maxn];
int t = 1;
int tab[1000][1000];
int res = 0;
int n, k;
int fin(int x) {
  if (F[x] != x) F[x] = fin(F[x]);
  return F[x];
}
void uni(int a, int b) {
  a = fin(a);
  b = fin(b);
  if (a != b) {
    F[a] = b;
    r[b] += r[a];
  }
}
int num(int x, int y) { return (x - 1) * n + y - 1; }
void flip(int x, int y, int X) {
  if (1 <= x && x <= n && 1 <= y && y <= n)
    if (tab[x][y] == 0) r[fin(num(x, y))] += X;
}
int dolicz(int x, int y) {
  if (tab[x][y]) return 0;
  x = fin(num(x, y));
  if (stan[x] == t) return 0;
  stan[x] = t;
  return r[x];
}
void spr(int x, int y) {
  int cnt = 0;
  if (y > 1)
    for (int i = x; i < x + k; i++) cnt += dolicz(i, y - 1);
  if (y + k <= n)
    for (int i = x; i < x + k; i++) cnt += dolicz(i, y + k);
  if (x > 1)
    for (int i = y; i < y + k; i++) cnt += dolicz(x - 1, i);
  if (x + k <= n)
    for (int i = y; i < y + k; i++) cnt += dolicz(x + k, i);
  res = max(res, cnt);
  t++;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    for (int j = 1; j <= n; j++) {
      if (s[j - 1] == 'X')
        tab[i][j] = 1;
      else
        tab[i][j] = 0;
      F[num(i, j)] = num(i, j);
      if (tab[i][j] == 0) r[num(i, j)] = 1;
    }
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      for (auto s : mov) {
        int ii = i + s.first;
        int jj = j + s.second;
        if (1 <= ii && ii <= n && 1 <= jj && jj <= n && tab[i][j] == 0 &&
            tab[ii][jj] == 0)
          uni(num(i, j), num(ii, jj));
      }
  int x = 1;
  int y = 0;
  for (int i = 1; i <= k; i++)
    for (int j = 1; j < k; j++) flip(i, j, -1);
  while (x + k - 1 <= n) {
    if (y <= 1) {
      while (y + k <= n) {
        for (int j = 0; j < k; j++) {
          flip(x + j, y, 1);
          flip(x + j, y + k, -1);
        }
        y++;
        spr(x, y);
      }
    } else {
      while (y > 1) {
        for (int j = 0; j < k; j++) {
          flip(x + j, y - 1, -1);
          flip(x + j, y + k - 1, 1);
        }
        y--;
        spr(x, y);
      }
    }
    for (int i = y; i < y + k; i++) flip(x, i, 1), flip(x + k, i, -1);
    x++;
    if (x + k - 1 <= n) spr(x, y);
  }
  cout << res + k * k;
  return 0;
}
