#include <stdio.h>
#include <stdlib.h>

int main(void) {
    int n1, n2;

    if (scanf("%d", &n1) != 1 || n1 < 0)
    { 
        printf("Invalid input\n"); 
    return 0;
    }
    int *a = (int*)malloc(sizeof(int) * n1);
    if (a== NULL){
       printf("memory allocation failed\n");
       return 1;
    }
    for (int i = 0; i < n1; ++i) {
    if (scanf("%d", &a[i])!=1){
        free(a);
        return 0;
    }
}
    if (scanf("%d", &n2) != 1 || n2 < 0) 
    {  free(a);
      printf("Invalid input\n");
      return 0;
      }
    int *b = (int*)malloc(sizeof(int) *n2);
    if (b == NULL){
        free(a);
        printf("Memory allocation failed");
        return 0;
    }
    for (int i = 0; i < n2; ++i) {
        if (scanf("%d", &b[i]!=)
{
    free(a);
    free(b);
    return 0;
}
        
    }
    int found = 0;
    for (int i = 0; i + 1 < n2 -1&& !found; ++i) {
        int tailLen = n2 - (i + 1);               
        for (int s = 0; s + tailLen <= n1 && !found; ++s) {
            int ok = 1;
            for (int k = 0; k < tailLen; ++k) {
                if (a[s + k] != b[i + 1 + k]) { ok = 0; break; }
            }
            if (ok) {
                printf("%d\n", b[i]);            
                found = 1;
            }
        }
    }

    if (!found) {
        printf("The two lists do not intersect\n");
    }

    free(a);
    free(b);
    return 0;
}