#include <bits/stdc++.h>
using namespace std;
const signed long long Infinity = 1000000100;
const long double Epsilon = 1e-9;
template <typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
  return os << "(" << p.first << "," << p.second << ")";
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& V) {
  os << "[";
  for (int(i) = (0); (i) < (int(V.size())); (i)++)
    os << V[i] << ((i == int(V.size()) - 1) ? "" : ",");
  return os << "]";
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& S) {
  os << "(";
  for (__typeof(S.begin()) i = S.begin(); i != S.end(); ++i)
    os << *i << (*i == *S.rbegin() ? "" : ",");
  return os << ")";
}
template <typename T, typename U>
ostream& operator<<(ostream& os, const map<T, U>& M) {
  os << "{";
  for (__typeof(M.begin()) i = M.begin(); i != M.end(); ++i)
    os << *i << (*i.first == M.rbegin()->first ? "" : ",");
  return os << "}";
}
int Rep[555][555];
int REP[555 * 555];
int Siz[555 * 555];
int Find(int a) {
  if (REP[a] != a) REP[a] = Find(REP[a]);
  return REP[a];
}
void Union(int a, int b) {
  a = Find(a);
  b = Find(b);
  if (a == b) return;
  REP[a] = b;
  Siz[b] += Siz[a];
}
char T[555][555];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
void U(int a, int b) {
  if (T[a][b] == 'X') return;
  for (int(i) = (0); (i) <= (3); (i)++) {
    if (T[a + dx[i]][b + dy[i]] == 'X') continue;
    Union(Rep[a][b], Rep[a + dx[i]][b + dy[i]]);
    Rep[a + dx[i]][b + dy[i]] = Rep[a][b] = Find(Rep[a][b]);
  }
}
int state[555 * 555];
int sum;
int ans;
void add(int a) {
  if (state[a] == 0) sum += Siz[a];
  state[a]++;
}
void rem(int a) {
  state[a]--;
  if (state[a] == 0) sum -= Siz[a];
}
int n;
void a(int a, int b) {
  if (T[a][b] == 'X' and a != 0 and b != 0 and a != n + 1 and b != n + 1) sum++;
}
void r(int a, int b) {
  if (T[a][b] == 'X' and a != 0 and b != 0 and a != n + 1 and b != n + 1) sum--;
}
int main() {
  int k;
  scanf("%d%d", &n, &k);
  for (int(i) = (1); (i) <= (n); (i)++)
    for (int(j) = (1); (j) <= (n); (j)++) {
      scanf(" %c", &T[i][j]);
      Rep[i][j] = i + (j - 1) * n;
      REP[i + (j - 1) * n] = i + (j - 1) * n;
      Siz[i + (j - 1) * n] = T[i][j] != 'X';
    }
  for (int(i) = (0); (i) <= (n + 1); (i)++)
    T[i][0] = T[0][i] = T[i][n + 1] = T[n + 1][i] = 'X';
  for (int(i) = (1); (i) <= (n); (i)++)
    for (int(j) = (1); (j) <= (n); (j)++) U(i, j);
  for (int(i) = (0); (i) <= (n); (i)++) {
    if (i + k + 1 > n + 1) break;
    for (int(j) = (0); (j) <= (555 * 555 - 1); (j)++) state[j] = 0;
    sum = 0;
    for (int(j) = (0); (j) <= (n + 1); (j)++) {
      for (int(l) = (1); (l) <= (k); (l)++) add(Find(Rep[i + l][j]));
      if (j > 0) add(Find(Rep[i][j - 1]));
      if (j > 0) add(Find(Rep[i + k + 1][j - 1]));
      if (j > 0)
        for (int(l) = (1); (l) <= (k); (l)++) a(i + l, j - 1);
      if (j - k - 2 >= 0)
        for (int(l) = (1); (l) <= (k); (l)++) rem(Find(Rep[i + l][j - k - 2]));
      if (j - k - 1 >= 0) rem(Find(Rep[i][j - k - 1]));
      if (j - k - 1 >= 0) rem(Find(Rep[i + k + 1][j - k - 1]));
      if (j - k - 1 >= 0)
        for (int(l) = (1); (l) <= (k); (l)++) r(i + l, j - k - 1);
      ans = max(ans, sum);
    }
  }
  printf("%d\n", ans);
  return 0;
}
