import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void log(A...)(A arg) {
    stderr.writeln(arg);
}
int size(T)(in T s) {
    return cast(int)s.length;
}

void main() {
    int N, M; scanf("%d %d\n", &N, &M);
    auto A = readln.chomp.split(" ").map!(to!int).array;
    auto B = readln.chomp.split(" ").map!(to!int).array;
    assert(N == A.size);
    assert(M == B.size);

    int calc(int a, int b, int p, int q) {
        int a_score = 0, b_score = 0;
        for (int i = p; i < a; i++) {
            if (A[i] < 0) continue;
            a_score += A[i];
        }
        for (int i = q; i < b; i++) {
            if (B[i] < 0) continue;
            b_score += B[i];
        }
        //log([a, b, p, q], [a_score, b_score]);
        return a_score - b_score;
    }

    int[Tuple!(int, int, int, int, int, int)] cache;
    int dfs(int w, int a, int b, int p, int q, int pass_count) {
        if (pass_count == 2) return 0;
        auto key = tuple(w, a, b, p, q, pass_count);
        if (key in cache) return cache[key];
        int ret = (w == 0 ? int.min / 4 : int.max / 4);
        if (w == 0) {
            ret = max(ret, dfs( (w + 1) % 2, a, b, a, b, pass_count + (a == p && b == q) ) + calc(a, b, p, q));
            if (a < A.size)
                ret = max(ret, dfs( (w + 1) % 2, a + 1, b, p, A[a] == -1 ? b : q, 0 ));
        } else {
            ret = min(ret, dfs( (w + 1) % 2, a, b, a, b, pass_count + (a == p && b == q) ) + calc(a, b, p, q));
            if (b < B.size) 
                ret = min(ret, dfs( (w + 1) % 2, a, b + 1, B[b] == -1 ? a : p, q, 0 ));
        }
        return cache[key] = ret;
    }

    writeln(dfs(0, 0, 0, 0, 0, false));

    /*
    foreach (k, v; cache) {
        writeln(k, " -> ", v);
    }
    */


}