#include <bits/stdc++.h>
using namespace std;
const int N = 501;
char a[N][N + 1];
int n, k;
int ncmp[4][N][N];
int cmp[N][N];
bool cused[N][N];
int cmpSz[N * N];
int dx[4]{1, 0, -1, 0};
int dy[4]{0, 1, 0, -1};
bool inBoard(int x, int y) { return x >= 0 && y >= 0 && x < n && y < n; }
void dfs(int x, int y, int t) {
  cused[x][y] = true;
  cmpSz[t]++;
  cmp[x][y] = t;
  for (int i = 0; i < 4; i++) {
    int xx = x + dx[i];
    int yy = y + dy[i];
    if (inBoard(xx, yy) && a[xx][yy] != 'X') {
      if (!cused[xx][yy]) dfs(xx, yy, t);
    }
  }
}
int when[N * N];
int cnt[N * N];
int add(int& a, int id, int time) {
  if (when[id] == time) {
    cnt[id]++;
    if (cnt[id] == 1) {
      a += cmpSz[id];
    }
  } else {
    when[id] = time;
    cnt[id] = 1;
    a += cmpSz[id];
  }
}
int remove(int& a, int id, int time) {
  cnt[id] -= 1;
  if (cnt[id] == 0) {
    a -= cmpSz[id];
  }
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%s", a[i]);
  }
  memset(ncmp, -1, sizeof(ncmp));
  memset(cmp, -1, sizeof(cmp));
  int nof = 0;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (cused[i][j] || a[i][j] == 'X') continue;
      dfs(i, j, ++nof);
      ans = max(ans, cmpSz[nof]);
    }
  }
  int time = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (a[i][j] == '.') continue;
      for (int d = 0; d < 4; d++) {
        int xx = i + dx[d];
        int yy = j + dy[d];
        if (inBoard(xx, yy)) {
          if (cmp[xx][yy] != -1) {
            ncmp[d][i][j] = cmp[xx][yy];
          }
        }
      }
    }
  }
  for (int i = 0; i < n; i++, time++) {
    if (i + k - 1 >= n) break;
    int curVal = 0;
    for (int ii = 0; ii < k; ii++) {
      for (int j = 0; j < k; j++) {
        if (a[i + ii][j] == 'X')
          curVal++;
        else {
          add(curVal, cmp[i + ii][j], time);
        }
        for (int d = 0; d < 4; d++) {
          if (ncmp[d][i + ii][j] != -1) {
            add(curVal, ncmp[d][i + ii][j], time);
          }
        }
      }
    }
    ans = max(ans, curVal);
    for (int j = 0; j < n; j++) {
      if (j + k >= n) continue;
      for (int ii = 0; ii < k; ii++) {
        if (a[ii + i][j] == 'X') {
          curVal--;
        } else {
          remove(curVal, cmp[i + ii][j], time);
        }
        for (int d = 0; d < 4; d++) {
          if (ncmp[d][ii + i][j] != -1) {
            remove(curVal, ncmp[d][i + ii][j], time);
          }
        }
      }
      for (int ii = 0; ii < k; ii++) {
        if (a[ii + i][j + k] == 'X') {
          curVal++;
        } else {
          add(curVal, cmp[i + ii][j + k], time);
        }
        for (int d = 0; d < 4; d++) {
          if (ncmp[d][ii + i][j + k] != -1) {
            add(curVal, ncmp[d][i + ii][j + k], time);
          }
        }
      }
      ans = max(ans, curVal);
    }
  }
  printf("%d", ans);
  return 0;
}
