#include <bits/stdc++.h>
using namespace std;

int n, m;
int a[50];
int b[50];

int score[51][51][51][51][2][2];
int memo[51][51][51][51][2];
bool check[51][51][51][51][2];

int getPassScore(int i, int j, int beforeI, int beforeJ, int turn, int player){
    if(i == beforeI && j == beforeJ){
        return 0;
    }

    int temp = score[i][j][beforeI][beforeJ][turn][player];
    if(temp != -1){
        return temp;
    }

    if((player == 0 && i == beforeI) || (player == 1 && j == beforeJ)){
        score[i][j][beforeI][beforeJ][turn][player] = 0;
        return 0;
    }

    //cout << i << " " << j << " " << beforeI << " " << beforeJ << " " << turn << " " << player << endl;

    int ret = 0;
    if(turn == 0){
        if(player == 0){
            if(j != beforeJ && b[j - 1] == -1){
                ret = 0;
            }
            else{
                ret = getPassScore(i, j - 1, beforeI, beforeJ, 1, player);
            }
        }
        else{
            if(b[j - 1] == -1){
                ret = getPassScore(i, j - 1, beforeI, beforeJ, 1, player);
            }
            else{
                ret =  getPassScore(i, j - 1, beforeI, beforeJ, 1, player) + b[j - 1];
            }
        }
    }
    else{
        if(player == 0){
            if(a[i - 1] == -1){
                ret = getPassScore(i - 1, j, beforeI, beforeJ, 0, player);
            }
            else{
                ret = getPassScore(i - 1, j, beforeI, beforeJ, 0, player) + a[i - 1];
            }
        }
        else{
            if(i != beforeI && a[i - 1] == -1){
                ret = 0;
            }
            else{
                ret = getPassScore(i - 1, j, beforeI, beforeJ, 0, player);
            }
        }
    }

    score[i][j][beforeI][beforeJ][turn][player] = ret;
    return ret;
}

int getScore(int i, int j, int beforeI, int beforeJ, int turn){

    if(i == n && j == m)
    {   
        //cout << beforeI << " " << beforeJ << endl;
        //cout << "score" << getPassScore(i, j, beforeI, beforeJ, turn, 0) << " " << getPassScore(i, j, beforeI, beforeJ, turn, 1) << endl;
        return getPassScore(i, j, beforeI, beforeJ, turn, 0) - getPassScore(i, j, beforeI, beforeJ, turn, 1);
    }

    if(check[i][j][beforeI][beforeJ][turn]){
        return memo[i][j][beforeI][beforeJ][turn];
    }

    check[i][j][beforeI][beforeJ][turn] = true;

    if(turn == 0){
        int putScore = 0;
        if(i == n){
            putScore = -(1 << 30);
        }
        else{
            putScore = getScore(i + 1, j, beforeI, beforeJ, 1);
        }

        int passScore = 0;
        if(i == beforeI && j == beforeJ){
            if(j == m){
                passScore = 0;
            }
            else{
                passScore = min(0, getScore(i, j + 1, i, j, 0));
            }
        }
        else{
            passScore = getScore(i, j, i, j, 1) + getPassScore(i, j, beforeI, beforeJ, turn, 0) - getPassScore(i, j, beforeI, beforeJ, turn, 1);
        }
        int ret = max(putScore, passScore);

        memo[i][j][beforeI][beforeJ][turn] = ret;
        //cout << i << " " << j << " " << beforeI << " " << beforeJ << " " << turn << " " << ret << endl;
        return ret;
    }
    else{
        int putScore = 0;
        if(j == m){
            putScore = (1 << 30);
        }
        else{
            putScore = getScore(i, j + 1, beforeI, beforeJ, 0);
        }
        int passScore = 0;

        if(i == beforeI && j == beforeJ){
            if(i == n){
                passScore = 0;
            }
            else{
                passScore = max(0, getScore(i + 1, j, i, j, 1));
            }
        }
        else{
            passScore = getScore(i, j, i, j, 0) + getPassScore(i, j, beforeI, beforeJ, turn, 0) - getPassScore(i, j, beforeI, beforeJ, turn, 1);
        }
        int ret = min(putScore, passScore);

        memo[i][j][beforeI][beforeJ][turn] = ret;
        //cout << i << " " << j << " " << beforeI << " " << beforeJ << " " << turn << " " << ret << endl; 
        return ret;
    }
}

int main(){
    
    cin >> n >> m;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    for(int j = 0; j < m; j++){
        cin >> b[j];
    }

    memset(score, -1, sizeof(score));
    memset(memo, -1, sizeof(memo));
    
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= m; j++){
            for(int beforeI = 0; beforeI <= i; beforeI++){
                for(int beforeJ = 0; beforeJ <= j; beforeJ++){
                    check[i][j][beforeI][beforeJ][0] = false;
                    check[i][j][beforeI][beforeJ][1] = false;
                }
            }
        }
    }

    int ans = getScore(0, 0, 0, 0, 0);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 174588