#include <bits/stdc++.h>
#define int long long
#define ll long long
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x) cout << #x << " = " << (x) << endl;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define pb push_back
#define all(v) (v).begin(), (v).end()
/*
struct segtree {
    int seg[5010];
    int mum;
    void init(int n)
    {
        mum = 1ll;
        while (mum < n)
            mum <<= 1;
        for (int i = 0; i < mum * 2; i++)
            seg[i] = 0;
    }
    void add(int k, int x)
    {
        k += mum - 1;
        seg[k] = x;
        while (k > 0)
            k = (k - 1) / 2;

        seg[k] = max(seg[k * 2 + 1], seg[k * 2 + 2]);
    }
    int get(int a, int b, int k, int l, int r)
    {
        if (b <= 1 || r <= a)
            return 0ll;
        if (a <= 1 && r <= b)
            return seg[k];
        else {
            int vl = get(a, b, k * 2 + 1, l, (l + r) / 2);
            int vr = get(a, b, k * 2 + 2, (l + r) / 2, r);
            return max(vl, vr);
        }
    }
    int get(int a, int b)
    {
        return get(a, b, 0, 0, mum);
    }
};
*/
int N, M, A[5010], B[5010][210];
int d[5010];
int t[5010][5010];

const int BT = 64 * 128 * 2;
struct segtree {
    int index;
    ll seg[BT];
    int mum;

    void init(int n, int ind)
    {
        index = ind;
        mum = 1;
        while (mum < n)
            mum <<= 1;
        for (int i = 0; i < mum * 2; i++)
            seg[i] = 0;
    }
    void add(int k, ll x)
    {
        k += mum - 1;
        seg[k] = x;
        while (k > 0) {
            k = (k - 1) / 2;
            //seg[k] = max(seg[k * 2 + 1], seg[k * 2 + 2]);
            if (B[seg[k * 2 + 1]][index] > B[seg[k * 2 + 2]][index]) {
                seg[k] = seg[k * 2 + 1];
            } else {
                seg[k] = seg[k * 2 + 2];
            }
        }
    }
    ll get(int a, int b, int k, int l, int r)
    {
        if (b <= l || r <= a)
            return 5000;
        if (a <= l && r <= b)
            return seg[k];
        else {
            ll vl = get(a, b, k * 2 + 1, l, (l + r) / 2);
            ll vr = get(a, b, k * 2 + 2, (l + r) / 2, r);
            //return max(vl, vr);
            if (B[vl][index] > B[vr][index]) {
                return vl;
            } else {
                return vr;
            }
        }
    }
    ll get(int a, int b)
    {
        return get(a, b, 0, 0, mum);
    }
};
//segtree seg[210];
segtree seg;
/*
signed main()
{
    segtree s;
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        B[i][0] = i * i;
    }
    s.init(N, 0);
    FOR(i, 0, N)
    {
        s.add(i, B[i][0]);
    }
    FOR(i, 0, N)
    {
        FOR(j, i, N)
        {
            cout << i << " " << j << " " << s.get(i, j) << endl;
        }
    }
    return 0;
}
*/

void calc(int m, int l, int r)
{
    //int opt = seg[m].get(l, r);
    int opt = seg.get(l, r);
    int b = B[opt][m];
    t[l][r - 1] += b;
    t[l][opt - 1] -= b;
    t[opt + 1][r - 1] -= b;
    t[opt + 1][opt - 1] += b;
    if (r - l == 1)
        return;
    if (opt != l) {
        /*
        cout << 'l' << endl;
        dump(m);
        dump(opt);
        dump(l);
        dump(r);
        cout << endl;
        */
        calc(m, l, opt);
    }
    if (opt != (r - 1)) {
        /*
        cout << 'r' << endl;
        dump(m);
        dump(opt);
        dump(l);
        dump(r);
        cout << endl;
        */
        calc(m, opt + 1, r);
    }
}
void solve()
{
    FOR(i, 1, N)
    d[i] = d[i - 1] + A[i - 1];
    /* 
    FOR(i, 0, M)
    {
        seg[i].init(N, i);
        FOR(j, 0, N)
        {
            seg[i].add(j, j);
        }
        calc(i, 0, N);
    }
    */
    FOR(i, 0, M)
    {
        seg.init(N, i);
        FOR(j, 0, N)
        {
            seg.add(j, j);
        }
        calc(i, 0, N);
    }
    /*
    for (int j = N - 1; j >= 0; j--) {
        for (int i = 0; i < N; i++) {
            cout << t[i][j] << " ";
        }
        cout << endl;
    }
    cout << endl;
*/

    for (int j = 0; j < N; j++) {
        for (int i = 1; i < N; i++) {
            t[i][j] += t[i - 1][j];
        }
    }
    for (int i = 0; i < N; i++) {
        for (int j = N - 1; j >= 0; j--) {
            t[i][j] += t[i][j + 1];
        }
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i; j < N; j++) {
            ans = max(ans, t[i][j] + d[i] - d[j]);
        }
    }
    cout << ans << endl;
}

signed main()
{
    cin >> N >> M;
    FOR(i, 0, N - 1)
    {
        cin >> A[i];
    }
    FOR(i, 0, N)
    {
        FOR(j, 0, M)
        {
            cin >> B[i][j];
        }
    }
    solve();
    return 0;
}


Measured memory_bytes: 204800