#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

int dp[51][51][52][52][2][2];
int sm[2][51];
vi a[2];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    a[0].resize(n),a[1].resize(m);
    rep(i,n){
        cin >> a[0][i];
        cmx(a[0][i],0);
        sm[0][i+1] = sm[0][i] + a[0][i];
    }
    rep(i,m){
        cin >> a[1][i];
        cmx(a[1][i],0);
        sm[1][i+1] = sm[1][i] + a[1][i];
    }
    rep(i,n+1){
        rep(j,m+1){
            rep(k,n+2){
                rep(l,m+2){
                    rep(p,2){
                        dp[i][j][k][l][p][0] = -INF;
                        dp[i][j][k][l][p][1] = INF;
                    }
                }
            }
        }
    }
    rrep(i,n+1){
        rrep(j,m+1){
            rrep(k,i+1){
                rrep(p,j+1){
                    rrep(l,2){
                        rrep(q,2){
                            if(q == 0){
                                if(l == 1 && i == k && j == p){
                                    cmx(dp[i][j][k][p][l][q],0);
                                }else{
                                    if(i == k && j == p){
                                        cmx(dp[i][j][k][p][l][q],dp[i][j][i][j][1][1]+sm[0][i]-sm[0][k]-sm[1][j]+sm[1][p]);
                                    }else{
                                        cmx(dp[i][j][k][p][l][q],dp[i][j][i][j][0][1]+sm[0][i]-sm[0][k]-sm[1][j]+sm[1][p]);
                                    }
                                }
                                if(i < n){
                                    if(a[0][i] == 0){
                                        cmx(dp[i][j][k][p][l][q],dp[i+1][j][k][j][0][1]);
                                    }else{
                                        cmx(dp[i][j][k][p][l][q],dp[i+1][j][k][p][0][1]);
                                    }
                                }
                            }else{
                                if(l == 1 && i == k && j == p){
                                    cmn(dp[i][j][k][p][l][q],0);
                                }else{
                                    if(i == k && j == p){
                                        cmn(dp[i][j][k][p][l][q],dp[i][j][i][j][1][0]+sm[0][i]-sm[0][k]-sm[1][j]+sm[1][p]);
                                    }else{
                                        cmn(dp[i][j][k][p][l][q],dp[i][j][i][j][0][0]+sm[0][i]-sm[0][k]-sm[1][j]+sm[1][p]);
                                    }
                                }
                                if(j < m){
                                    if(a[1][j] == 0){
                                        cmn(dp[i][j][k][p][l][q],dp[i][j+1][i][p][0][0]);
                                    }else{
                                        cmn(dp[i][j][k][p][l][q],dp[i][j+1][k][p][0][0]);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    cout << dp[0][0][0][0][0][0] << "\n";
    return 0;
}



Measured memory_bytes: 113092