#include <bits/stdc++.h>
using namespace std;
int n, k, sl, tp[250005], dd[505][505], cnt, cur, sum, ans, mem[250005];
char s[505][505];
void dfs(int x, int y) {
  cnt++;
  dd[x][y] = sl;
  for (__typeof(-1) fx = (-1), _b = (1); fx <= _b; fx++)
    for (__typeof(-1) fy = (-1), _b = (1); fy <= _b; fy++)
      if (fx * fy == 0 && s[x + fx][y + fy] == '.' && !dd[x + fx][y + fy])
        dfs(x + fx, y + fy);
}
void update(int i1, int j1, int i2, int j2, int k) {
  i1 = max(i1, 0), i2 = min(i2, n - 1);
  j1 = max(j1, 0), j2 = min(j2, n - 1);
  for (__typeof(i1) i = (i1), _b = (i2); i <= _b; i++)
    for (__typeof(j1) j = (j1), _b = (j2); j <= _b; j++)
      if (s[i][j] == '.') {
        mem[dd[i][j]] += k;
        if (k == -1 && mem[dd[i][j]] == 0) cur -= tp[dd[i][j]];
        if (k == 1 && mem[dd[i][j]] == 1) cur += tp[dd[i][j]];
      }
}
void run(int i1, int j1, int i2, int j2, int k) {
  for (__typeof(i1) i = (i1), _b = (i2); i <= _b; i++)
    for (__typeof(j1) j = (j1), _b = (j2); j <= _b; j++)
      sum += k * int(s[i][j] == 'X');
}
int main() {
  scanf("%d%d", &n, &k);
  for (__typeof(0) i = (0), _b = (n - 1); i <= _b; i++) scanf("%s", s[i]);
  for (__typeof(0) i = (0), _b = (n - 1); i <= _b; i++)
    for (__typeof(0) j = (0), _b = (n - 1); j <= _b; j++)
      if (s[i][j] == '.' && !dd[i][j]) {
        sl++;
        cnt = 0;
        dfs(i, j);
        tp[sl] = cnt;
      }
  int ans = 0;
  for (__typeof(0) i = (0), _b = (n - k); i <= _b; i++) {
    memset(mem, 0, sizeof(mem));
    cur = sum = 0;
    update(i - 1, 0, i + k, k, 1);
    update(i - 1, k, i - 1, k, -1);
    update(i + k, k, i + k, k, -1);
    run(i, 0, i + k - 1, k - 1, 1);
    ans = max(ans, cur + sum);
    for (__typeof(1) j = (1), _b = (n - k); j <= _b; j++) {
      update(i, j - 2, i + k - 1, j - 2, -1);
      update(i - 1, j - 1, i - 1, j - 1, -1);
      update(i + k, j - 1, i + k, j - 1, -1);
      update(i, j + k, i + k - 1, j + k, 1);
      update(i - 1, j + k - 1, i - 1, j + k - 1, 1);
      update(i + k, j + k - 1, i + k, j + k - 1, 1);
      run(i, j - 1, i + k - 1, j - 1, -1);
      run(i, j + k - 1, i + k - 1, j + k - 1, 1);
      ans = max(ans, cur + sum);
    }
  }
  cout << ans << endl;
}
