#include <bits/stdc++.h>
using namespace std;
const long long int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353;
const long long inf = 1LL << 61;
const long long int M = 1e6 + 500;
const long long int ths = 1LL << 40;
const long long int NN = 5e3 + 6;
const long long int maxN = 2007;
long long int dp[maxN][maxN];
void add(long long int r1, long long int c1, long long int r2,
         long long int c2) {
  dp[r1][c1]++;
  dp[r1][c2 + 1]--;
  dp[r2 + 1][c1]--;
  dp[r2 + 1][c2 + 1]++;
  return;
}
void solve() {
  long long int n, k;
  cin >> n >> k;
  char a[n + 2][n + 2];
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 1; j <= n; j++) {
      cin >> a[i][j];
    }
  }
  for (long long int i = 1; i <= n; i++) {
    long long int l, r;
    for (l = 1; l <= n; l++) {
      if (a[i][l] == 'B') break;
    }
    for (r = n; r >= 0; r--) {
      if (a[i][r] == 'B') break;
    }
    if (r - l + 1 > k) continue;
    if (l > n) {
      add(1, 1, n - k + 1, n - k + 1);
    } else {
      add(max(i - k + 1, 1LL), max(r - k + 1, 1LL), min(i, n - k + 1),
          min(l, n - k + 1));
    }
  }
  for (long long int i = 1; i <= n; i++) {
    long long int l, r;
    for (l = 1; l <= n; l++) {
      if (a[l][i] == 'B') break;
    }
    for (r = n; r >= 0; r--) {
      if (a[r][i] == 'B') break;
    }
    if (r - l + 1 > k) continue;
    if (l > n) {
      add(1, 1, n - k + 1, n - k + 1);
    } else {
      add(max(r - k + 1, 1LL), max(i - k + 1, 1LL), min(l, n - k + 1),
          min(i, n - k + 1));
    }
  }
  long long int ans = 0;
  for (long long int i = 1; i <= n - k + 1; i++) {
    for (long long int j = 1; j <= n - k + 1; j++) {
      dp[i][j] += dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans;
  cout << "\n";
  return;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
