#include <bits/stdc++.h>
using namespace std;
const int N = 505;
int n, K;
char s[N][N];
int par[N * N], sz[N * N];
int id(int x, int y) { return x * n + y; }
int getfa(int x) { return par[x] == x ? x : par[x] = getfa(par[x]); }
void merge(int a, int b) {
  int pa = getfa(a), push_back = getfa(b);
  if (pa != push_back) {
    sz[pa] += sz[push_back];
    par[push_back] = pa;
  }
}
int sum[N][N];
int cnt[N * N];
int Plus(int x, int y) {
  if (s[x][y] == 'X') return 0;
  int c = par[id(x, y)];
  cnt[c]++;
  if (cnt[c] == 1) return sz[c];
  return 0;
}
int Del(int x, int y) {
  if (s[x][y] == 'X') return 0;
  int c = par[id(x, y)];
  cnt[c]--;
  if (cnt[c] == 0) return sz[c];
  return 0;
}
int Sum(int a, int b, int c, int d) {
  int r = sum[c][d];
  if (b) r -= sum[c][b - 1];
  if (a) r -= sum[a - 1][d];
  if (a && b) r += sum[a - 1][b - 1];
  return r;
}
int main() {
  scanf("%d%d", &n, &K);
  for (int i = 0; i < n; ++i) scanf("%s", s[i]);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j) {
      int k = id(i, j);
      par[k] = k;
      sz[k] = s[i][j] == '.';
      sum[i][j] = s[i][j] == '.';
    }
  for (int i = 1; i < n; ++i)
    for (int j = 0; j < n; ++j) sum[i][j] += sum[i - 1][j];
  for (int i = 0; i < n; ++i)
    for (int j = 1; j < n; ++j) sum[i][j] += sum[i][j - 1];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      if (s[i][j] == '.') {
        int c = id(i, j), nc = 0;
        if (i != n && s[i + 1][j] == '.') nc = id(i + 1, j), merge(c, nc);
        if (j != n && s[i][j + 1] == '.') nc = id(i, j + 1), merge(c, nc);
      }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j) {
      int c = id(i, j);
      getfa(c);
    }
  int ans = 0;
  for (int i = 0; i + K <= n; ++i) {
    fill(cnt, cnt + N * N, 0);
    int all = 0;
    for (int k = 0; k < K; ++k)
      for (int t = 0; t < K; ++t) all += Plus(k + i, t);
    int j = 0;
    if (i != 0)
      for (int k = 0; k < K; ++k) all += Plus(i - 1, j + k);
    if (i + K != n)
      for (int k = 0; k < K; ++k) all += Plus(i + K, j + k);
    if (j + K != n)
      for (int k = 0; k < K; ++k) all += Plus(i + k, j + K);
    ans = max(ans, all + K * K - Sum(i, j, i + K - 1, j + K - 1));
    for (++j; j + K <= n; ++j) {
      if (j - 1)
        for (int k = 0; k < K; ++k) all -= Del(i + k, j - 2);
      if (i) all -= Del(i - 1, j - 1);
      if (i + K != n) all -= Del(i + K, j - 1);
      if (j + K != n)
        for (int k = 0; k < K; ++k) all += Plus(i + k, j + K);
      if (i) all += Plus(i - 1, j + K - 1);
      if (i + K != n) all += Plus(i + K, j + K - 1);
      ans = max(ans, all + K * K - Sum(i, j, i + K - 1, j + K - 1));
    }
  }
  printf("%d\n", ans);
  return 0;
}
