/*
TASK:cannibal
LANG:C++
KEYW: EASY!!!!
*/

#include <cstdio>

const int MAXN = 1 << 7;
const int N = 102;

int v1[MAXN], v2[MAXN];

int main () {
	int i;
    for (i = 0; i < N; ++i) scanf ("%d", v1 + i);
    for (i = 0; i < N; ++i) scanf ("%d", v2 + i);
    int s3 = 0;
    for (i = 0; i < N; ++i) if (v1[i] != -1) s3 += v1[i];
    s3 %= 3;
    for (i = 0; i < N && (v2[i] == -1 || v2[i] == v1[i]); ++i);
    fprintf (stderr, "i == %d\n", i);
    if (i == N) {
		printf ("%d\n", s3);//try to save the others
    } else {
		printf ("%d\n", (v2[i] + v1[i] - s3 + 9) % 3);
	}

    return 0;    
}
