#include <bits/stdc++.h>
using namespace std;
int bx[5] = {0, 0, 0, 1, -1};
int by[5] = {0, 1, -1, 0, 0};
int f[510][510], val[510 * 510], number[510 * 510], vis[510][510], a[510][510],
    last[510 * 510];
int now, i, j, cnt, k, K, x, ans, n;
char s[510];
struct cc {
  int x, y;
} c[510 * 510];
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
inline void write(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
inline int bfs(int x, int y) {
  int h, t, xx, yy, i;
  c[1].x = x;
  c[1].y = y;
  h = 0;
  t = 1;
  vis[x][y] = cnt;
  while (h < t) {
    h++;
    x = c[h].x;
    y = c[h].y;
    for (i = 1; i <= 4; i++) {
      xx = x + bx[i];
      yy = y + by[i];
      if (xx && yy && xx <= n && yy <= n && a[xx][yy] && vis[xx][yy] == 0) {
        t++;
        c[t].x = xx;
        c[t].y = yy;
        vis[xx][yy] = cnt;
      }
    }
  }
  return t;
}
int main() {
  n = read();
  K = read();
  for (i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    for (j = 1; j <= n; j++) a[i][j] = (s[j] == '.');
  }
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++)
      if (vis[i][j] == 0 && a[i][j]) {
        cnt++;
        val[cnt] = bfs(i, j);
      }
  for (i = 1; i <= K; i++)
    for (j = 1; j <= K; j++) {
      if (vis[i][j]) {
        x = vis[i][j];
        number[x]++;
        if (number[x] == 1) f[1][1] += val[x];
      } else
        f[1][1]++;
    }
  if (K + 1 <= n) {
    for (i = 1; i <= K; i++) {
      x = vis[i][K + 1];
      if (x) {
        number[x]++;
        if (number[x] == 1) f[1][1] += val[x];
      }
    }
    for (j = 1; j <= K; j++) {
      x = vis[K + 1][j];
      if (x) {
        number[x]++;
        if (number[x] == 1) f[1][1] += val[x];
      }
    }
  }
  for (j = 1; j <= cnt; j++) last[j] = number[j];
  for (i = 1; i + K - 1 <= n; i++) {
    if (i != 1) {
      now = f[i - 1][1];
      for (j = 1; j <= cnt; j++) number[j] = last[j];
      for (k = 1; k <= K; k++) {
        if (i > 2 && vis[i - 2][k]) {
          x = vis[i - 2][k];
          number[x]--;
          if (number[x] == 0) now -= val[x];
        }
        if (i > 1 && vis[i - 1][k] == 0) now--;
        if (i + K <= n && vis[i + K][k]) {
          x = vis[i + K][k];
          number[x]++;
          if (number[x] == 1) now += val[x];
        }
        if (vis[i + K - 1][k] == 0) now++;
      }
      if (i + K - 1 <= n && K + 1 <= n && vis[i + K - 1][K + 1]) {
        x = vis[i + K - 1][K + 1];
        number[x]++;
        if (number[x] == 1) now += val[x];
      }
      if (K + 1 <= n && vis[i - 1][K + 1]) {
        x = vis[i - 1][K + 1];
        number[x]--;
        if (number[x] == 0) now -= val[x];
      }
      for (j = 1; j <= cnt; j++) last[j] = number[j];
      f[i][1] = now;
    }
    for (j = 2; j + K - 1 <= n; j++) {
      now = f[i][j - 1];
      for (k = i; k <= i + K - 1; k++) {
        if (j > 2 && vis[k][j - 2]) {
          x = vis[k][j - 2];
          number[x]--;
          if (number[x] == 0) now -= val[x];
        }
        if (j > 1 && vis[k][j - 1] == 0) now--;
        if (j + K - 1 < n && vis[k][j + K]) {
          x = vis[k][j + K];
          number[x]++;
          if (number[x] == 1) now += val[x];
        }
        if (vis[k][j + K - 1] == 0) now++;
      }
      if (i > 1 && j > 1 && vis[i - 1][j - 1]) {
        x = vis[i - 1][j - 1];
        number[x]--;
        if (number[x] == 0) now -= val[x];
      }
      if (i > 1 && vis[i - 1][j + K - 1]) {
        x = vis[i - 1][j + K - 1];
        number[x]++;
        if (number[x] == 1) now += val[x];
      }
      if (i + K <= n && j > 1 && vis[i + K][j - 1]) {
        x = vis[i + K][j - 1];
        number[x]--;
        if (number[x] == 0) now -= val[x];
      }
      if (i + K <= n && vis[i + K][j + K - 1]) {
        x = vis[i + K][j + K - 1];
        number[x]++;
        if (number[x] == 1) now += val[x];
      }
      f[i][j] = now;
    }
  }
  for (i = 1; i + K - 1 <= n; i++)
    for (j = 1; j + K - 1 <= n; j++) ans = max(ans, f[i][j]);
  write(ans);
}
