c
#include 
#include 

#define MAX_SIZE 10

int readList(int **list, int *size) {
    if (scanf("%d", size) != 1 || *size < 0 || *size > MAX_SIZE) {
        return 0; // Invalid input
    }

    *list = (int *)calloc(*size, sizeof(int)); // Start with calloc

    if (*list == NULL) {
        return 0; // Memory allocation failed
    }

    for (int i = 0; i < *size; ++i) {
        if (scanf("%d", &(*list)[i]) != 1) {
            free(*list);
            return 0; // Invalid input
        }
    }
    return 1; // Success
}

int findIntersection(int *a, int n1, int *b, int n2) {
    for (int i = 0; i < n2 - 1; ++i) {
        for (int s = 0; s <= n1 - (n2 - (i + 1)); ++s) {
            int match = 1;
            for (int k = 0; k < n2 - (i + 1); ++k) {
                if (a[s + k] != b[i + 1 + k]) {
                    match = 0; // Not a match
                    break;
                }
            }
            if (match) {
                return b[i]; // Found intersection
            }
        }
    }
    return -1; // No intersection found
}

int main(void) {
    int *a, *b;
    int n1, n2;

    if (!readList(&a, &n1) || !readList(&b, &n2)) {
        printf("Invalid input\n");
        return 0;
    }

    int intersection = findIntersection(a, n1, b, n2);

    if (intersection != -1) {
        printf("%d\n", intersection);
    } else {
        printf("The two lists do not intersect\n");
    }

    free(a);
    free(b);
    return 0;
}