#include <bits/stdc++.h>
using namespace std;
int n, k, v[505][505], b[250005], cur = 1, cnt;
char a[505][505];
void dfs(int first, int second) {
  if (v[first][second] || a[first][second] == 'X') return;
  v[first][second] = cur;
  cnt++;
  dfs(first + 1, second);
  dfs(first, second + 1);
  dfs(first - 1, second);
  dfs(first, second - 1);
}
int f[250005] = {0}, first = 0, curans = 0, ans = 0;
void solve() {
  cin >> n >> k;
  for (int i = 0; i < n + 2; i++) {
    for (int j = 0; j < n + 2; j++) {
      if (i == 0 || j == 0 || i == n + 1 || j == n + 1)
        a[i][j] = 'X';
      else
        cin >> a[i][j];
    }
  }
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < n + 1; j++) {
      if (!v[i][j] && a[i][j] == '.') {
        cnt = 0;
        dfs(i, j);
        b[cur] = cnt;
        cur++;
      }
    }
  }
  for (int i = 1; i < k + 1; i++) {
    for (int j = 1; j < k + 1; j++) {
      if (a[i][j] == 'X') first++;
    }
  }
  for (int i = 0; i < k + 2; i++) {
    for (int j = (i == 0 || i == k + 1); j < k + 2 - (i == 0 || i == k + 1);
         j++) {
      if (a[i][j] == '.') {
        f[v[i][j]]++;
        if (f[v[i][j]] == 1) curans += b[v[i][j]];
      }
    }
  }
  ans = max(ans, curans + first);
  for (int i = 0; i < n - k + 1; i++) {
    int tempans = curans, tempx = first, tempf[cur + 1];
    for (int j = 0; j < cur + 1; j++) tempf[j] = f[j];
    for (int j = 0; j < n - k; j++) {
      for (int l = 1; l < k + 1; l++) {
        if (a[i + l][j + k + 1] == 'X') first++;
        if (a[i + l][j + 1] == 'X') first--;
      }
      for (int l = 0; l < k + 2; l++) {
        if (a[i + l][j + k + 2 - (l == 0 || l == k + 1)] == '.') {
          f[v[i + l][j + k + 2 - (l == 0 || l == k + 1)]]++;
          if (f[v[i + l][j + k + 2 - (l == 0 || l == k + 1)]] == 1)
            curans += b[v[i + l][j + k + 2 - (l == 0 || l == k + 1)]];
        }
        if (a[i + l][j + (l == 0 || l == k + 1)] == '.') {
          f[v[i + l][j + (l == 0 || l == k + 1)]]--;
          if (f[v[i + l][j + (l == 0 || l == k + 1)]] == 0)
            curans -= b[v[i + l][j + (l == 0 || l == k + 1)]];
        }
      }
      ans = max(ans, curans + first);
    }
    curans = tempans;
    first = tempx;
    for (int j = 0; j < cur + 1; j++) f[j] = tempf[j];
    for (int l = 1; l < k + 1; l++) {
      if (a[i + k + 1][l] == 'X') first++;
      if (a[i + 1][l] == 'X') first--;
    }
    for (int l = 0; l < k + 2; l++) {
      if (a[i + k + 2 - (l == 0 || l == k + 1)][l] == '.') {
        f[v[i + k + 2 - (l == 0 || l == k + 1)][l]]++;
        if (f[v[i + k + 2 - (l == 0 || l == k + 1)][l]] == 1)
          curans += b[v[i + k + 2 - (l == 0 || l == k + 1)][l]];
      }
      if (a[i + (l == 0 || l == k + 1)][l] == '.') {
        f[v[i + (l == 0 || l == k + 1)][l]]--;
        if (f[v[i + (l == 0 || l == k + 1)][l]] == 0)
          curans -= b[v[i + (l == 0 || l == k + 1)][l]];
      }
    }
    if (i == n - k) break;
    ans = max(ans, curans + first);
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}
