#include       <bits/stdc++.h>
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#define           el   '\n'
#define           fi   first
#define           se   second        
#define           ll   long long
#define           pb   push_back
#define           pf   push_front
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/         

using namespace std; 

signed main()
{
    
    ios_base::sync_with_stdio(false);  cin.tie(0); cout.tie(0); 
    
    int n, k; cin >> n >> k;
    int p[n+1][n+1]; 

    for (int i=0; i<=n; i++) p[i][0] = p[0][i] = 0;

    for (int i=1; i<=n; i++)
        for (int j=1; j<=n; j++) {
            int x; cin >> x;
            p[i][j] = p[i][j-1] + p[i-1][j] - p[i-1][j-1] + x;
        }

    int res = 0;

    for (int i=k; i<=n; i++)
        for (int j=k; j<=n; j++)
            res = max(res, p[i][j] - p[i-k][j] - p[i][j-k] + p[i-k][j-k]);

    cout << res; 

    
   
   return (0 ^ 0);
}