#include <bits/stdc++.h>
template <class t>
inline void read(t &s) {
  s = 0;
  register int f = 1;
  register char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();
  s *= f;
  return;
}
template <class t, class... A>
inline void read(t &x, A &...a) {
  read(x);
  read(a...);
}
template <class t>
inline void write(t x) {
  if (x < 0) putchar('-'), x = -x;
  int buf[21], top = 0;
  while (x) buf[++top] = x % 10, x /= 10;
  if (!top) buf[++top] = 0;
  while (top) putchar(buf[top--] ^ '0');
  return;
}
inline void setIn(std::string s) {
  freopen(s.c_str(), "r", stdin);
  return;
}
inline void setOut(std::string s) {
  freopen(s.c_str(), "w", stdout);
  return;
}
inline void setIO(std::string s = "") {
  setIn(s + ".in");
  setOut(s + ".out");
  return;
}
template <class t>
inline bool ckmin(t &x, t y) {
  if (x > y) {
    x = y;
    return 1;
  }
  return 0;
}
template <class t>
inline bool ckmax(t &x, t y) {
  if (x < y) {
    x = y;
    return 1;
  }
  return 0;
}
inline int lowbit(int x) { return x & (-x); }
const int MaxN = 505;
const int dir[4][2] = {1, 0, 0, 1, -1, 0, 0, -1};
char s[MaxN][MaxN];
int cnt[MaxN][MaxN];
int f[MaxN][MaxN];
int col[MaxN][MaxN], vis[MaxN][MaxN], ok[MaxN * MaxN], S[MaxN * MaxN], scc, n,
    K;
int magius;
inline void dfs(int x, int y) {
  vis[x][y] = 1, ++S[scc], col[x][y] = scc;
  for (int i = 0; i < 4; ++i) {
    register int nx = x + dir[i][0], ny = y + dir[i][1];
    if (!nx || nx > n || !ny || ny > n || vis[nx][ny] || s[nx][ny] == 'X')
      continue;
    dfs(nx, ny);
  }
}
inline void add(int x, int y) {
  ++cnt[x][y];
  if (!(ok[col[x][y]]++)) magius += S[col[x][y]];
}
inline void del(int x, int y) {
  --cnt[x][y];
  if (!(--ok[col[x][y]])) magius -= S[col[x][y]];
}
inline int calc(int u, int v, int x, int y) {
  return f[x][y] - f[u - 1][y] - f[x][v - 1] + f[u - 1][v - 1];
}
signed main(void) {
  read(n, K);
  for (int i = 1; i <= n; ++i) std::scanf("%s", s[i] + 1);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      f[i][j] = f[i - 1][j] + f[i][j - 1] - f[i - 1][j - 1] + (s[i][j] == '.');
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      if (!vis[i][j] && s[i][j] == '.') ++scc, dfs(i, j);
  register int ans = 0;
  for (int i = 1; i <= n - K + 1; ++i) {
    for (int j = 0; j < K; ++j)
      for (int k = 1; k < K; ++k) add(i + j, k);
    for (int j = 1; j <= n - K + 1; ++j) {
      for (int k = 0; k < K; ++k) add(i + k, j + K - 1);
      if (i)
        for (int k = 0; k < K; ++k) add(i - 1, j + k);
      if (j)
        for (int k = 0; k < K; ++k) add(i + k, j - 1);
      if (i + K <= n)
        for (int k = 0; k < K; ++k) add(i + K, j + k);
      if (j + K <= n)
        for (int k = 0; k < K; ++k) add(i + k, j + K);
      ckmax(ans, magius - calc(i, j, i + K - 1, j + K - 1) + K * K);
      for (int k = 0; k < K; ++k) del(i + k, j);
      if (i)
        for (int k = 0; k < K; ++k) del(i - 1, j + k);
      if (j)
        for (int k = 0; k < K; ++k) del(i + k, j - 1);
      if (i + K <= n)
        for (int k = 0; k < K; ++k) del(i + K, j + k);
      if (j + K <= n)
        for (int k = 0; k < K; ++k) del(i + k, j + K);
    }
    for (int j = 0; j < K; ++j)
      for (int k = n - K + 2; k <= n; ++k) del(i + j, k);
  }
  write(ans), std::puts("");
  return 0;
}
