#include <bits/stdc++.h>
using namespace std;
int dummy;
int n, k;
bool t[510][510];
int c[510][510];
int cnts[510 * 510], bordering[510 * 510], obscured[510 * 510];
int destroyed, csum;
int m = 0;
int dfs(int va, int vb, int k) {
  vector<pair<int, int>> f;
  f.push_back({va, vb});
  c[va][vb] = k;
  int sq = 1;
  while (f.size()) {
    int a, b;
    pair<int, int> p = f[f.size() - 1];
    f.pop_back();
    a = p.first;
    b = p.second;
    pair<int, int> ch[4] = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}};
    for (int i = 0; i < 4; i++) {
      int r = a + ch[i].first, s = b + ch[i].second;
      if (r < 0 || r >= n || s < 0 || s >= n) continue;
      if (!t[r][s] || c[r][s] != -1) continue;
      c[r][s] = k;
      f.push_back({r, s});
      sq++;
    }
  }
  return sq;
}
void components(void) {
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      if (!t[i][j] || c[i][j] != -1) continue;
      cnts[m] = dfs(i, j, m);
      m++;
    }
}
vector<pair<int, int>> neighbours(int r, int s) {
  vector<pair<int, int>> v;
  for (int i = s; i < s + k; i++) {
    if (r > 0) v.push_back({r - 1, i});
    if (r + k < n) v.push_back({r + k, i});
  }
  for (int i = r; i < r + k; i++) {
    if (s > 0) v.push_back({i, s - 1});
    if (s + k < n) v.push_back({i, s + k});
  }
  return v;
}
void lose(int r, int s) {
  for (pair<int, int> p : neighbours(r, s)) {
    int comp = c[p.first][p.second];
    bordering[comp]--;
    if (bordering[comp] == 0) csum -= cnts[comp];
  }
}
void gain(int r, int s) {
  for (pair<int, int> p : neighbours(r, s)) {
    int comp = c[p.first][p.second];
    bordering[comp]++;
    if (bordering[comp] == 1) csum += cnts[comp];
  }
}
void recalculate(int r, int s) {
  for (int i = 0; i < m; i++) bordering[i] = obscured[i] = 0;
  destroyed = csum = 0;
  for (int i = r; i < r + k; i++) {
    for (int j = s; j < s + k; j++) {
      int comp = c[i][j];
      if (!t[i][j])
        destroyed++;
      else
        obscured[comp]++;
      if (obscured[comp] == cnts[comp]) csum += cnts[comp];
    }
  }
  gain(r, s);
}
void obscure(int r, int s) {
  for (int i = s; i < s + k; i++) {
    int comp = c[r][i];
    if (comp == -1) {
      destroyed++;
      continue;
    }
    obscured[comp]++;
    if (obscured[comp] == cnts[comp]) csum += cnts[comp];
  }
}
void unobscure(int r, int s) {
  for (int i = s; i < s + k; i++) {
    int comp = c[r][i];
    if (comp == -1) {
      destroyed--;
      continue;
    }
    obscured[comp]--;
    if (obscured[comp] == cnts[comp] - 1) csum -= cnts[comp];
  }
}
int main(void) {
  dummy = scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      char s;
      while ((s = getchar()) != '.' && s != 'X')
        ;
      t[i][j] = s == '.';
      c[i][j] = -1;
    }
  }
  int m = 0;
  components();
  for (int s = 0; s + k <= n; s++) {
    for (int r = 0; r + k <= n; r++) {
      if (r == 0) {
        recalculate(r, s);
      } else {
        lose(r - 1, s);
        gain(r, s);
        unobscure(r - 1, s);
        obscure(r + k - 1, s);
      }
      int ma = destroyed + csum;
      if (ma > m) m = ma;
    }
  }
  printf("%d\n", m);
}
