#include <bits/stdc++.h>
const int MAXN = 511;
const int MAXQ = 500001;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
int n, k, v[MAXN][MAXN], c[MAXQ];
char map[MAXN][MAXN];
bool flag[MAXQ];
void bfs(int x, int y, char ch) {
  static int qx[MAXQ], qy[MAXQ];
  static int cnt = 0;
  cnt++;
  int left = 0, right = 0;
  right++;
  qx[right] = x;
  qy[right] = y;
  v[x][y] = cnt;
  while (left < right) {
    left++;
    for (int dir = 0; dir < 4; dir++) {
      int nx = qx[left] + dx[dir], ny = qy[left] + dy[dir];
      if (1 <= nx && nx <= n && 1 <= ny && ny <= n && !v[nx][ny] &&
          ch == map[nx][ny]) {
        v[nx][ny] = cnt;
        right++;
        qx[right] = nx;
        qy[right] = ny;
      }
    }
  }
  c[cnt] = right;
}
int main() {
  std::cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    std::cin >> map[i] + 1;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (!v[i][j]) bfs(i, j, map[i][j]);
  int answer = 0;
  for (int i = 1; i <= n - k + 1; i++) {
    for (int p = i; p <= i + k - 1; p++)
      for (int q = 1; q <= k; q++) {
        if (map[p][q] == '.') {
          c[v[p][q]]--;
        }
      }
    for (int j = 1; j <= n - k + 1; j++) {
      int tmp = k * k;
      for (int p = i; p <= i + k - 1; p++) {
        if (j > 1 && !flag[v[p][j - 1]] && map[p][j - 1] == '.') {
          tmp += c[v[p][j - 1]];
          flag[v[p][j - 1]] = true;
        }
        if (j + k <= n && !flag[v[p][j + k]] && map[p][j + k] == '.') {
          tmp += c[v[p][j + k]];
          flag[v[p][j + k]] = true;
        }
      }
      for (int p = j; p <= j + k - 1; p++) {
        if (i > 1 && !flag[v[i - 1][p]] && map[i - 1][p] == '.') {
          tmp += c[v[i - 1][p]];
          flag[v[i - 1][p]] = true;
        }
        if (i + k <= n && !flag[v[i + k][p]] && map[i + k][p] == '.') {
          tmp += c[v[i + k][p]];
          flag[v[i + k][p]] = true;
        }
      }
      answer = std::max(answer, tmp);
      for (int p = i; p <= i + k - 1; p++) {
        if (j > 1 && map[p][j - 1] == '.') {
          flag[v[p][j - 1]] = false;
        }
        if (j + k <= n && map[p][j + k] == '.') {
          flag[v[p][j + k]] = false;
        }
      }
      for (int p = j; p <= j + k - 1; p++) {
        if (i > 1 && map[i - 1][p] == '.') {
          flag[v[i - 1][p]] = false;
        }
        if (i + k <= n && map[i + k][p] == '.') {
          flag[v[i + k][p]] = false;
        }
      }
      if (j < n - k + 1) {
        for (int p = i; p <= i + k - 1; p++) {
          if (map[p][j] == '.') {
            c[v[p][j]]++;
          }
          if (map[p][j + k] == '.') {
            c[v[p][j + k]]--;
          }
        }
      }
    }
    for (int p = i; p <= i + k - 1; p++)
      for (int q = n - k + 1; q <= n; q++) {
        if (map[p][q] == '.') {
          c[v[p][q]]++;
        }
      }
  }
  printf("%d\n", answer);
  return 0;
}
