#include <bits/stdc++.h>
using namespace std;
char W[510][510];
int p[250010];
int sz[250010];
int n, k;
int find(int x) {
  if (x == p[x]) return x;
  return p[x] = find(p[x]);
}
void join(int x, int y) {
  int xroot = find(x), yroot = find(y);
  if (xroot != yroot) {
    sz[yroot] += sz[xroot];
    p[xroot] = yroot;
  }
}
bool v[510][510];
int iter;
int movx[] = {1, -1, 0, 0};
int movy[] = {0, 0, 1, -1};
void dfs(int x, int y) {
  v[x][y] = true;
  for (int i = 0; i < 4; i++) {
    int nx = x + movx[i], ny = y + movy[i];
    if (nx < 0 || nx >= n || ny < 0 || ny >= n) continue;
    if (v[nx][ny]) continue;
    if (W[nx][ny] != W[x][y]) continue;
    join(x * n + y, nx * n + ny);
    dfs(nx, ny);
  }
}
int M[250010];
int neigh(int x, int y) {
  int sum = 0;
  for (int i = 0; i < k; i++) {
    if (x - 1 < 0) break;
    if (W[x - 1][y + i] == 'X') continue;
    int C = find((x - 1) * n + y + i);
    if (M[C] == iter) continue;
    M[C] = iter;
    sum += sz[C];
  }
  for (int i = 0; i < k; i++) {
    if (x + k >= n) break;
    if (W[x + k][y + i] == 'X') continue;
    int C = find((x + k) * n + y + i);
    if (M[C] == iter) continue;
    M[C] = iter;
    sum += sz[C];
  }
  for (int i = 0; i < k; i++) {
    if (y - 1 < 0) break;
    if (W[x + i][y - 1] == 'X') continue;
    int C = find((x + i) * n + y - 1);
    if (M[C] == iter) continue;
    M[C] = iter;
    sum += sz[C];
  }
  for (int i = 0; i < k; i++) {
    if (y + k >= n) break;
    if (W[x + i][y + k] == 'X') continue;
    int C = find((x + i) * n + y + k);
    if (M[C] == iter) continue;
    M[C] = iter;
    sum += sz[C];
  }
  return sum;
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n * n; i++) {
    p[i] = i;
    sz[i] = 1;
  }
  for (int i = 0; i < n; i++) scanf("%s", W[i]);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (!v[i][j] && W[i][j] != 'X') {
        dfs(i, j);
      }
    }
  }
  int best = 0;
  iter = 1;
  for (int i = 0; i + k <= n; i++) {
    int li = 0;
    for (int j = 0; j < n; j++) {
      for (int r = 0; r < k; r++) {
        if (W[i + r][j] == 'X') continue;
        int C = find((i + r) * n + j);
        sz[C]--;
      }
      if (j >= k) {
        for (int r = 0; r < k; r++) {
          if (W[i + r][li] == 'X') continue;
          int C = find((i + r) * n + li);
          sz[C]++;
        }
        li++;
      }
      if (j >= k - 1) {
        int cursum = k * k + neigh(i, li);
        iter++;
        best = max(best, cursum);
      }
    }
    while (li < n) {
      for (int r = 0; r < k; r++) {
        if (W[i + r][li] == 'X') continue;
        int C = find((i + r) * n + li);
        sz[C]++;
      }
      li++;
    }
  }
  printf("%d\n", best);
  return 0;
}
