/+ dub.sdl:
    name "A"
    dependency "dcomp" version=">=0.4.0"
+/
extern(C) __gshared string[] rt_options = ["gcopt=heapSizeFactor:1.1"];

import std.stdio, std.algorithm, std.conv, std.range;
import std.container;
// import dcomp.scanner;
 
int main() {
    auto sc = new Scanner(stdin);
    int n, m;
    long[] a;
    sc.read(n, m, a); a ~= 0;
    long[][] b = new long[][](n, m);
    b.each!((ref v) => sc.read(v));
 
    long[][] mp = new long[][](n+1, n+1);
    foreach (num; 0..m) {
        auto v = iota(0, n).map!(k => b[k][num]).enumerate.array.sort!"a.value > b.value".array;
        auto tr = redBlackTree!int([-1, n]);
        foreach (x; v) {
            int i = x.index.to!int;
            long d = x.value;
            int lw = tr.lowerBound(i).back + 1;
            int up = tr.upperBound(i).front - 1;
            tr.insert(i);
            mp[lw][i] += d;
            mp[lw][up+1] -= d;
            mp[i+1][i] -= d;
            mp[i+1][up+1] += d;
        }
    }
 
    foreach (i; 0..n) {
        foreach (j; 1..n) {
            mp[i][j] += mp[i][j-1];
        }
    }
    foreach (j; 0..n) {
        foreach (i; 1..n) {
            mp[i][j] += mp[i-1][j];
        }
    }
 
    long ans = -(10L^^18);
    foreach (l; 0..n) {
        long dist = 0;
        foreach (r; l..n) {
            //[l, r]
            ans = max(ans, mp[l][r] - dist);
            dist += a[r];
        }
    }
    writeln(ans);
    return 0;
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;

class Scanner {
    import std.stdio : File;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeChar, isStaticArray, isArray; 
    import std.algorithm : map;
    File f;
    this(File f) {
        this.f = f;
    }
    string[] buf;
    private bool succ() {
        while (!buf.length) {
            if (f.eof) return false;
            buf = f.readln.split;
        }
        return true;
    }
    private bool readSingle(T)(ref T x) {
        if (!succ()) return false;
        static if (isArray!T) {
            alias E = ElementType!T;
            static if (isSomeChar!E) {
                //string or char[10] etc
                x = buf.front;
                buf.popFront;
            } else {
                static if (isStaticArray!T) {
                    //static
                    assert(buf.length == T.length);
                }
                x = buf.map!(to!E).array;
                buf.length = 0;                
            }
        } else {
            x = buf.front.to!T;
            buf.popFront;            
        }
        return true;
    }
    int read(T, Args...)(ref T x, auto ref Args args) {
        if (!readSingle(x)) return 0;
        static if (args.length == 0) {
            return 1;
        } else {
            return 1 + read(args);
        }
    }
}

unittest {
    import std.path : buildPath;
    import std.file : tempDir;
    import std.algorithm : equal;
    import std.stdio : File;
    string fileName = buildPath(tempDir, "kyuridenanmaida.txt");
    auto fout = File(fileName, "w");
    fout.writeln("1 2 3");
    fout.writeln("ab cde");
    fout.writeln("1.0 1.0 2.0");
    fout.close;
    Scanner sc = new Scanner(File(fileName, "r"));
    int a;
    int[2] b;
    char[2] c;
    string d;
    double e;
    double[] f;
    sc.read(a, b, c, d, e, f);
    assert(a == 1);
    assert(equal(b[], [2, 3]));
    assert(equal(c[], "ab"));
    assert(equal(d, "cde"));
    assert(e == 1.0);
    assert(equal(f, [1.0, 2.0]));
}


Measured memory_bytes: 225788