#include <bits/stdc++.h>
using namespace std;
vector<string> vs;
int visi[501][501];
int vis[501][501];
int typ[501][501];
int siz[501][501];
int cc, si;
int ff[501 * 501];
int n, k;
void print(int a[501][501]) {
  int i, j;
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      cout << a[i][j] << " ";
    }
    cout << endl;
  }
}
int del(int r, int c) {
  if (r >= 0 && c >= 0 && r < n && c < n) {
    ff[typ[r][c]]--;
    if (ff[typ[r][c]] == 0) return -siz[r][c];
  }
  return 0;
}
int insert(int r, int c) {
  if (r >= 0 && c >= 0 && r < n && c < n) {
    ff[typ[r][c]]++;
    if (ff[typ[r][c]] == 1) return siz[r][c];
  }
  return 0;
}
int delX(int r, int c) {
  if (r >= 0 && c >= 0 && r < n && c < n && vs[r][c] != 'X') {
    ff[typ[r][c]]--;
    if (ff[typ[r][c]] == 0) return -siz[r][c];
  }
  return 0;
}
int insertX(int r, int c) {
  if (r >= 0 && c >= 0 && r < n && c < n && vs[r][c] != 'X') {
    ff[typ[r][c]]++;
    if (ff[typ[r][c]] == 1) return siz[r][c];
  }
  return 0;
}
int delcol(int r1, int r2, int c) {
  if (r1 < 0 || r2 >= n || c < 0 || c >= n) return 0;
  int i, an = 0;
  for (i = r1; i <= r2; i++) {
    an += del(i, c);
  }
  return an;
}
int delcolX(int r1, int r2, int c) {
  if (r1 < 0 || r2 >= n || c < 0 || c >= n) return 0;
  int i, an = 0;
  for (i = r1; i <= r2; i++) {
    if (vs[i][c] != 'X') an += del(i, c);
  }
  return an;
}
int incol(int r1, int r2, int c) {
  if (r1 < 0 || r2 >= n || c < 0 || c >= n) return 0;
  int i, an = 0;
  for (i = r1; i <= r2; i++) {
    an += insert(i, c);
  }
  return an;
}
int incolX(int r1, int r2, int c) {
  if (r1 < 0 || r2 >= n || c < 0 || c >= n) return 0;
  int i, an = 0;
  for (i = r1; i <= r2; i++) {
    if (vs[i][c] != 'X') an += insert(i, c);
  }
  return an;
}
int inrowX(int r, int c1, int c2) {
  if (r < 0 || r >= n || c1 < 0 || c2 >= n) return 0;
  int i, an = 0;
  for (i = c1; i <= c2; i++) {
    if (vs[r][i] != 'X') an += insert(r, i);
  }
  return an;
}
int inmat(int r1, int r2, int c1, int c2) {
  if (r1 < 0 || r2 >= n || c1 < 0 || c2 >= n) return 0;
  int i, j, an = 0;
  for (i = r1; i <= r2; i++) {
    for (j = c1; j <= c2; j++) {
      an += insert(i, j);
    }
  }
  return an;
}
int initial(int r) {
  int an = 0;
  an += inmat(r, r + k - 1, 0, k - 1);
  an += inrowX(r - 1, 0, k - 1);
  an += inrowX(r + k, 0, k - 1);
  an += incolX(r, r + k - 1, k);
  return an;
}
int moveon(int r, int c) {
  int an = 0;
  an += delX(r - 1, c - 1);
  an += delX(r + k, c - 1);
  an += delcolX(r, r + k - 1, c - 2);
  an += delcol(r, r + k - 1, c - 1);
  an += incolX(r, r + k - 1, c - 1);
  an += delcolX(r, r + k - 1, c + k - 1);
  an += incol(r, r + k - 1, c + k - 1);
  an += insertX(r - 1, c + k - 1);
  an += insertX(r + k, c + k - 1);
  an += incolX(r, r + k - 1, c + k);
  return an;
}
int dfs(int x, int y) {
  int s = 1;
  typ[x][y] = cc;
  vis[x][y] = 1;
  if (x - 1 >= 0 && vis[x - 1][y] == 0 && vs[x - 1][y] == '.')
    s += dfs(x - 1, y);
  if (y - 1 >= 0 && vis[x][y - 1] == 0 && vs[x][y - 1] == '.')
    s += dfs(x, y - 1);
  if (x + 1 < n && vis[x + 1][y] == 0 && vs[x + 1][y] == '.')
    s += dfs(x + 1, y);
  if (y + 1 < n && vis[x][y + 1] == 0 && vs[x][y + 1] == '.')
    s += dfs(x, y + 1);
  return s;
}
void dfsi(int x, int y) {
  siz[x][y] = si;
  visi[x][y] = 1;
  if (x - 1 >= 0 && visi[x - 1][y] == 0 && vs[x - 1][y] == '.') dfsi(x - 1, y);
  if (y - 1 >= 0 && visi[x][y - 1] == 0 && vs[x][y - 1] == '.') dfsi(x, y - 1);
  if (x + 1 < n && visi[x + 1][y] == 0 && vs[x + 1][y] == '.') dfsi(x + 1, y);
  if (y + 1 < n && visi[x][y + 1] == 0 && vs[x][y + 1] == '.') dfsi(x, y + 1);
}
int main() {
  int i, j, an, ans;
  string ss;
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> ss;
    vs.push_back(ss);
  }
  memset(vis, 0, sizeof(vis));
  memset(visi, 0, sizeof(visi));
  memset(ff, 0, sizeof(ff));
  memset(siz, 0, sizeof(siz));
  memset(typ, 0, sizeof(typ));
  cc = 0;
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      if (vs[i][j] == 'X') {
        cc++;
        typ[i][j] = cc;
        siz[i][j] = 1;
      } else if (vis[i][j] == 0) {
        cc++;
        si = dfs(i, j);
        dfsi(i, j);
      }
    }
  }
  ans = 0;
  for (i = 0; i <= n - k; i++) {
    memset(ff, 0, (cc + 1) * 4);
    an = initial(i);
    ans = max(an, ans);
    for (j = 1; j <= n - k; j++) {
      an += moveon(i, j);
      ans = max(an, ans);
    }
  }
  cout << ans << endl;
  return 0;
}
