#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  long long a[n + 2][n + 2], i, j;
  string s;
  memset(a, 0, sizeof(a));
  for (i = 1; i <= n; i++) {
    cin >> s;
    for (j = 1; j <= n; j++) a[i][j] = (s[j - 1] == 'B' ? 1 : 0);
  }
  long long left[n + 2][n + 2], right[n + 2][n + 2], top[n + 2][n + 2],
      bot[n + 2][n + 2];
  memset(left, 0, sizeof(left));
  memset(right, 0, sizeof(right));
  memset(bot, 0, sizeof(bot));
  memset(top, 0, sizeof(top));
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) left[i][j] = left[i][j - 1] + a[i][j];
    for (j = n; j >= 1; j--) right[i][j] = right[i][j + 1] + a[i][j];
  }
  for (j = 1; j <= n; j++) {
    for (i = 1; i <= n; i++) top[i][j] = top[i - 1][j] + a[i][j];
    for (i = n; i >= 1; i--) bot[i][j] = bot[i + 1][j] + a[i][j];
  }
  long long row[n + 2], col[n + 2];
  memset(row, 0, sizeof(row));
  memset(col, 0, sizeof(col));
  for (i = 1; i <= n; i++) row[i] = row[i - 1] + (right[i][1] == 0);
  for (j = 1; j <= n; j++) col[j] = col[j - 1] + (bot[1][j] == 0);
  long long dpcol[n + 2][n + 2];
  memset(dpcol, 0, sizeof(dpcol));
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      dpcol[i][j] = (top[i - 1][j] == 0);
      if (i + k <= n) dpcol[i][j] = dpcol[i][j] && (bot[i + k][j] == 0);
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) dpcol[i][j] += dpcol[i][j - 1];
  }
  long long dprow[n + 2][n + 2];
  memset(dprow, 0, sizeof(dprow));
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      dprow[i][j] = (left[i][j - 1] == 0);
      if (j + k <= n) dprow[i][j] = dprow[i][j] && (right[i][j + k] == 0);
    }
  }
  for (j = 1; j <= n; j++)
    for (i = 1; i <= n; i++) dprow[i][j] += dprow[i - 1][j];
  long long ans = 0;
  for (i = 1; i <= n - k + 1; i++) {
    for (j = 1; j <= n - k + 1; j++) {
      long long temp = col[j - 1] + col[n] - col[j + k - 1] + row[i - 1] +
                       row[n] - row[i + k - 1];
      temp += (dpcol[i][j + k - 1] - dpcol[i][j - 1]);
      temp += (dprow[i + k - 1][j] - dprow[i - 1][j]);
      ans = max(ans, temp);
    }
  }
  cout << ans << "\n";
  return 0;
}
