#include<bits/stdc++.h>#include<bits/extc++.h>usingnamespace std;#define _rep(i, a, b) for (int i = (a); i <= (b); ++i)#define _rev(i, a, b) for (int i = (a); i >= (b); --i)#define _for(i, a, b) for (int i = (a); i < (b); ++i)#define _rof(i, a, b) for (int i = (a); i > (b); --i)#define oo 0x3f3f3f3f#define ll long long#define db double#define eps 1e-8#define bin(x) cout << bitset<10>(x) << endl;#define what_is(x) cerr << #x << " is " << x << "s" << endl;#define met(a, b) memset(a, b, sizeof(a))#define all(x) x.begin(), x.end()#define pii pair<int, int>intnxt(){int ret;scanf("%d",&ret);return ret;}constint maxn =2e3+10;char mat[maxn][maxn];int sum[maxn][maxn];intmain(){int n =nxt(), k =nxt();_rep(i,1, n)scanf("%s", mat[i]+1);_rep(i,1, n){int l =0, r =0;_rep(j,1, n){if(mat[i][j]=='B'){if(l ==0)
l = j, r = j;else
r = j;}}if(l ==0){
sum[1][1]++;continue;}if(r - l +1> k)continue;int x1 =max(1, r - k +1), y1 =max(1, i - k +1), y2 = i, x2 = l;
sum[y1][x1]++, sum[y2 +1][x2 +1]++, sum[y2 +1][x1]--, sum[y1][x2 +1]--;}_rep(i,1, n){int u =0, d =0;_rep(j,1, n){if(mat[j][i]=='B'){if(u ==0)
u = j, d = j;else
d = j;}}if(u ==0){
sum[1][1]++;continue;}if(d - u +1> k)continue;int x1 =max(1, i - k +1), y1 =max(1, d - k +1), x2 = i, y2 = u;
sum[y1][x1]++, sum[y2 +1][x2 +1]++, sum[y2 +1][x1]--, sum[y1][x2 +1]--;}int ans =0;_rep(i,1, n){_rep(j,1, n){
sum[i][j]= sum[i][j]+ sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1];
ans =max(ans, sum[i][j]);}}
cout << ans << endl;}