#include <stdio.h>
#define ll long long
int main() {
    ll n, m, i, j;
    if (scanf("%lld %lld", &n, &m) != EOF) {
        ll ma[n + 1][m + 1];
        for(i = 0; i <= n; i++) {
            for(j = 0; j <= m; j++) {
                ma[i][j] = 0;
            }
        }
        // 遍历蛋糕的每一块,并记录前缀和
        for(i = 1; i <= n; i++) {
            for(j = 1; j <= m; j++) {
                if(scanf("%lld", &ma[i][j]) != EOF) {
                    ma[i][j] += ma[i - 1][j] + ma[i][j - 1] - ma[i - 1][j - 1];
                } else printf("error2\n");
            }
        }
        ll diff = 0;
        ll mindiff = 10000000000000ll;
        for(i = 1; i <= n; i++) {
            diff = ma[n][m] - 2 * ma[i][m];
            if(diff < 0) diff = -diff;
            mindiff = diff < mindiff ? diff : mindiff;
        }
        for(i = 1; i <= m; i++) {
            diff = ma[n][m] - 2 * ma[n][i];
            if(diff < 0) diff = -diff;
            mindiff = diff < mindiff ? diff : mindiff;
        }
        printf("%lld\n", mindiff);

    } else printf("error1\n");
    return 0;
}