#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    int matrica[n][m];
    int zbir[n + 1][m + 1];

    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= m; j++)
        {
            zbir[i][j] = 0;
        }
    }

    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            cin >> matrica[i][j];
            zbir[i][j] = zbir[i][j - 1] + matrica[i][j];
        }
    }



    int mini = INT_MAX;

    int broj = 0;
    if (n == 2)
    {
        for (int i = 1; i <= m; i++)
        {
            if (i == 1)
            {
                mini = min(mini, (zbir[1][m] - zbir[1][i]));
            }
            else
            {
                broj = (zbir[1][m] - zbir[1][i]) + zbir[1][i - 1];
                mini = min(mini, (zbir[1][m] - zbir[1][i]) + zbir[2][i - 1]);
            }
        }

        cout << mini << endl;
    }


    return 0;
}