#include <bits/stdc++.h>
int n, k, m = 0;
int now = 0;
bool r[510][510];
int f[510][510], sumy[510][510], sum[510][510], ran[510][510];
int record[300000], num[300000];
using namespace std;
int dfs(int x, int y) {
  if (!(x >= 0 && x < n && y >= 0 && y < n)) return 0;
  if (f[x][y] == 1) return 0;
  if (r[x][y]) return 0;
  ran[x][y] = m;
  r[x][y] = true;
  return dfs(x - 1, y) + dfs(x + 1, y) + dfs(x, y - 1) + dfs(x, y + 1) + 1;
}
void work(int x, int y) {
  record[ran[x][y]]++;
  if (record[ran[x][y]] == 1) now += num[ran[x][y]];
}
void work2(int x, int y) {
  record[ran[x][y]]--;
  if (record[ran[x][y]] == 0) now -= num[ran[x][y]];
}
bool check(int x, int y) {
  if (x > k - 2 && x < n + 1 && y > k - 2 && y < n + 1)
    return true;
  else
    return false;
}
int main() {
  scanf("%d%d", &n, &k);
  char c;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      cin >> c;
      if (c == 'X')
        f[i][j] = 1;
      else
        f[i][j] = 0;
    }
  for (int i = 0; i < n; i++) {
    sumy[i][0] = f[i][0];
    for (int j = 1; j < n; j++)
      if (j < k)
        sumy[i][j] = sumy[i][j - 1] + f[i][j];
      else
        sumy[i][j] = sumy[i][j - 1] + f[i][j] - f[i][j - k];
  }
  for (int j = 0; j < n; j++) {
    sum[0][j] = sumy[0][j];
    for (int i = 1; i < n; i++) {
      sum[i][j] = sum[i - 1][j] + sumy[i][j];
      if (i >= k) sum[i][j] -= sumy[i - k][j];
    }
  }
  memset(r, false, sizeof(r));
  memset(ran, 0, sizeof(ran));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if ((!r[i][j]) && (f[i][j] == 0)) {
        m++;
        num[m] = dfs(i, j);
      }
  num[0] = 0;
  int ans = 0;
  k += 2;
  for (int i = k - 2; i <= n; i++) {
    now = 0;
    memset(record, 0, sizeof(record));
    for (int z = max(0, i - k + 1); z <= i; z++) work(z, 0);
    for (int j = 1; j <= n; j++) {
      for (int z = max(0, i - k + 1); z <= i; z++) work(z, j);
      if (j >= k)
        for (int z = max(0, i - k + 1); z <= i; z++) work2(z, j - k);
      if (j >= k - 2) {
        work2(i, j);
        work2(i - k + 1, j);
        work2(i, j - k + 1);
        work2(i - k + 1, j - k + 1);
        ans = max(ans, sum[i - 1][j - 1] + now);
        work(i, j);
        work(i - k + 1, j);
        work(i, j - k + 1);
        work(i - k + 1, j - k + 1);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
