#include <bits/stdc++.h>
using namespace std;
#define TLHAdepzais1tg ios_base::sync_with_stdio(0);cin.tie();cout.tie(0);
#define ll long long
#define N 1007
#define fi first
#define se second
#define pii pair<ll,ll>
#define str string
int n,k;
ll a[N][N],ans=0;
ll pre[N][N];
int main()
{
    TLHAdepzais1tg;
    if(fopen("hv.inp","r"))
    {
        freopen("hv.inp","r",stdin);
        freopen("hv.out","w",stdout);
    }
    cin>>n>>k;
    pre[0][0]=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            cin>>a[i][j];
            pre[i][j]=pre[i][j-1]+pre[i-1][j]-pre[i-1][j-1]+a[i][j];
        }
    }
    for(int i=1;i<=n-k+1;i++)
    {
        for(int j=1;j<=n-k+1;j++)
        {
            int u=i+k-1;
            int v=j+k-1;
            ll res=pre[u][v]-pre[i-1][v]-pre[u][j-1]+pre[i-1][j-1];
            ans=max(ans,res);
        }
    }
    cout<<ans;
    return 0;
}

