#include <bits/stdc++.h>
using namespace std;
char s[2009][2009];
int a[2009][2009], b[2009][2009], n, k, L, R, sum, ans;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  for (int i = 1; i <= n; i++) {
    L = R = 0;
    for (int j = 1; j <= n; j++)
      if (s[i][j] == 'B') {
        if (L == 0) L = j;
        R = j;
      }
    if (L == 0)
      sum++;
    else if (R - L + 1 <= k) {
      for (int j = max(1, i - k + 1); j <= i; j++)
        a[j][max(1, R - k + 1)]++, a[j][min(L + 1, n + 1)]--;
    }
    L = R = 0;
    for (int j = 1; j <= n; j++)
      if (s[j][i] == 'B') {
        if (L == 0) L = j;
        R = j;
      }
    if (L == 0)
      sum++;
    else if (R - L + 1 <= k) {
      for (int j = max(1, i - k + 1); j <= i; j++)
        b[max(1, R - k + 1)][j]++, b[min(L + 1, n + 1)][j]--;
    }
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) a[i][j] += a[i][j - 1], b[j][i] += b[j - 1][i];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) ans = max(ans, a[i][j] + b[i][j]);
  ans += sum;
  printf("%d\n", ans);
  return 0;
}
