#include <bits/stdc++.h>
using namespace std;
template <class T>
T __sqr(const T x) {
  return x * x;
}
template <class T, class X>
inline T __pow(T a, X y) {
  T z = 1;
  for (int i = 1; i <= y; i++) {
    z *= a;
  }
  return z;
}
template <class T>
inline T gcd(T a, T b) {
  a = abs(a);
  b = abs(b);
  if (!b) return a;
  return __gcd(b, a % b);
}
template <class T>
inline T lcm(T a, T b) {
  a = abs(a);
  b = abs(b);
  return (a / __gcd(a, b)) * b;
}
inline bool ispow2(int x) { return (x != 0 && (x & (x - 1)) == 0); }
template <class T>
void UpdateMin(T &x, T y) {
  if (y < x) {
    x = y;
  }
}
template <class T>
void UpdateMax(T &x, T y) {
  if (x < y) {
    x = y;
  }
}
template <class T, class X, class Y>
inline T bigmod(T n, X m, Y mod) {
  unsigned long long ret = 1, a = n % mod;
  while (m) {
    if (m & 1) ret = (ret * a) % mod;
    m >>= 1;
    a = (a * a) % mod;
  }
  ret %= mod;
  return (T)ret;
}
template <class T, class Y>
inline T modinv(T n, Y mod) {
  return bigmod(n, mod - 2, mod);
}
template <class T, class X>
int getbit(T s, X i) {
  return (s >> i) & 1;
}
template <class T, class X>
T onbit(T s, X i) {
  return s | (T(1) << i);
}
template <class T, class X>
T offbit(T s, X i) {
  return s & (~(T(1) << i));
}
template <class T>
inline void read(T &n) {
  char c;
  for (c = getchar(); !(c >= '0' && c <= '9'); c = getchar())
    ;
  n = c - '0';
  for (c = getchar(); c >= '0' && c <= '9'; c = getchar()) n = n * 10 + c - '0';
}
void extended_euclid(long long a, long long b, long long &x, long long &y) {
  if (!b) {
    x = 1, y = 0;
    return;
  }
  long long first, second;
  extended_euclid(b, a % b, first, second);
  x = second;
  y = first - (a / b) * second;
}
pair<long long, pair<long long, long long> > extendedEuclid(long long a,
                                                            long long b) {
  long long x = 1, y = 0;
  long long xLast = 0, yLast = 1;
  long long q, r, m, n;
  while (a != 0) {
    q = b / a;
    r = b % a;
    m = xLast - q * x;
    n = yLast - q * y;
    xLast = x, yLast = y;
    x = m, y = n;
    b = a, a = r;
  }
  return make_pair(b, make_pair(xLast, yLast));
}
const long long mod[] = {0,          1000000007, 1000000009,
                         1000000021, 1000000033, 1000000097,
                         1000000093, 1000000097, 1000000103};
const long long base[] = {0,       1000003, 1000033, 1000037, 1000039,
                          1000081, 1000099, 1000117, 1000121};
char s[(500 + 20)][(500 + 20)];
int cnt[(500 + 20)][(500 + 20)];
int num[(500 + 20)][(500 + 20)];
int vis[(500 + 20)][(500 + 20)];
int tot[(500 + 20) * (500 + 20)], sr = 0;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int n, k;
void dfs(int x, int y) {
  vis[x][y] = true;
  num[x][y] = sr;
  tot[sr]++;
  for (int i = 0; i <= 3; i++) {
    int nx = x + dx[i];
    int ny = y + dy[i];
    if ((nx >= 1 && nx <= n) && (ny >= 1 && ny <= n) && s[nx][ny] == '.' &&
        !vis[nx][ny]) {
      dfs(nx, ny);
    }
  }
}
int cur[(500 + 20) * (500 + 20)], take[(500 + 20) * (500 + 20)];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s[i] + 1);
  }
  for (int i = 0; i <= n + 2; i++) {
    for (int j = 0; j <= n + 2; j++) {
      cnt[i][j] +=
          cnt[i][j - 1] + cnt[i - 1][j] - cnt[i - 1][j - 1] + (s[i][j] == 'X');
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (!vis[i][j] && s[i][j] == '.') {
        sr++;
        dfs(i, j);
      }
    }
  }
  int ans = 0, inside;
  for (int i = k + 1; i <= n + 1; i++) {
    for (int j = k + 1; j <= n + 1; j++) {
      i--;
      j--;
      int cp = cnt[i][j] - cnt[i][j - k] - cnt[i - k][j] + cnt[i - k][j - k];
      i++;
      j++;
      if (j == k + 1) {
        memset(cur, 0, sizeof cur);
        memset(take, 0, sizeof take);
        inside = 0;
        for (int p = i - k - 1; p <= i; p++) {
          for (int q = j - k - 1; q <= j; q++) {
            if ((p == i - k - 1 && q == j - k - 1) ||
                (p == i && q == j - k - 1) || (p == i - k - 1 && q == j) ||
                (p == i && q == j))
              continue;
            if (num[p][q]) {
              cur[num[p][q]]++;
              if (take[num[p][q]] == 0) {
                take[num[p][q]] = 1;
                inside += tot[num[p][q]];
              }
            }
          }
        }
        ans = max(ans, inside + cp);
      } else {
        int col = j;
        for (int row = i - k; row <= i - 1; row++) {
          if (num[row][col]) {
            cur[num[row][col]]++;
            if (take[num[row][col]] == 0) {
              take[num[row][col]] = 1;
              inside += tot[num[row][col]];
            }
          }
        }
        col = j - k - 1 - 1;
        for (int row = i - k; row <= i - 1; row++) {
          if (num[row][col]) {
            cur[num[row][col]]--;
            if (cur[num[row][col]] == 0) {
              take[num[row][col]] = 0;
              inside -= tot[num[row][col]];
            }
          }
        }
        col = j - k - 1;
        int row = i - k - 1;
        if (num[row][col]) {
          cur[num[row][col]]--;
          if (cur[num[row][col]] == 0) {
            take[num[row][col]] = 0;
            inside -= tot[num[row][col]];
          }
        }
        col = j - k - 1;
        row = i;
        if (num[row][col]) {
          cur[num[row][col]]--;
          if (cur[num[row][col]] == 0) {
            take[num[row][col]] = 0;
            inside -= tot[num[row][col]];
          }
        }
        col = j - 1;
        row = i - k - 1;
        if (num[row][col]) {
          cur[num[row][col]]++;
          if (take[num[row][col]] == 0) {
            take[num[row][col]] = 1;
            inside += tot[num[row][col]];
          }
        }
        col = j - 1;
        row = i;
        if (num[row][col]) {
          cur[num[row][col]]++;
          if (take[num[row][col]] == 0) {
            take[num[row][col]] = 1;
            inside += tot[num[row][col]];
          }
        }
        ans = max(ans, inside + cp);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
