#include <bits/stdc++.h>
using namespace std;
const int N = 2020;
char s[N][N];
int row[N][N], col[N][N];
bool U[N][N], D[N][N], L[N][N], R[N][N];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, k;
  cin >> n >> k;
  if (n == k) {
    cout << n + n << "\n";
    return 0;
  }
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  int ans = 0, has = 0;
  for (int i = 0; i < n; i++) {
    U[0][i] = (s[0][i] == 'W'), D[n - 1][i] = (s[n - 1][i] == 'W');
    L[i][0] = (s[i][0] == 'W'), R[i][n - 1] = (s[i][n - 1] == 'W');
    for (int j = 1; j < n; j++) {
      U[j][i] = U[j - 1][i] && s[j][i] == 'W',
      D[n - j - 1][i] = D[n - j][i] && s[n - j - 1][i] == 'W';
      L[i][j] = L[i][j - 1] && s[i][j] == 'W',
      R[i][n - j - 1] = R[i][n - j] && s[i][n - j - 1] == 'W';
    }
    has += U[n - 1][i] + L[i][n - 1];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j + k <= n && !L[i][n - 1] && (j == 0 || L[i][j - 1]) &&
          (j + k == n || R[i][j + k])) {
        ++col[max(0, i - k + 1)][j], --col[min(n, i + 1)][j];
      }
      if (i + k <= n && !U[n - 1][j] && (i == 0 || U[i - 1][j]) &&
          (i + k == n || D[i + k][j])) {
        ++row[i][max(0, j - k + 1)], --row[i][min(n, j + 1)];
      }
    }
  }
  for (int i = 0; i + k <= n; i++) {
    for (int j = 0; j + k <= n; j++) {
      if (j) row[i][j] += row[i][j - 1];
      if (i) col[i][j] += col[i - 1][j];
      ans = max(ans, has + row[i][j] + col[i][j]);
    }
  }
  cout << ans << "\n";
}
