#include <stdio.h>

 int main() {
     int n1,n2;
     scanf("%d",&n1);
     
     if (n1 < 0) 
     {
         printf("Invalid input");
         return 0;
     }
     
     int* list1 = (int*)malloc(n1 * sizeof(int));
     for (int i = 0; i < n1; i++){
         scanf("%d",&list1[i]);
     }
     
     scanf("%d",&n2);
     
     if(n2 < 0){
         printf("Invalid input");
         free(list1);
         return 0;
         
     }
     
     int* list2 = (int *)malloc(n2 * sizeof(int));
     for(int i = 0; i < n2; i++){
         scanf("%d", &list2[i]);
     }
     if(n1 == 0 || n2 == 0){
         printf("The two lists do not intersect");
         free (list1);
         free(list2);
         return 0;
     }
     
     
     int intersection = -1;
     for (int i = 0; i < n1; i++){
         for(int j = 0; j < n2; j++){
             int k1 = i, k2 = j;
             int match = 1;
             while (k1 < n1 && k2 < n2){
                 if(list1[k1] != list2[k2]){
                     match =0;
                     break;
             }
             k1++;
             k2++;
        }
             if(match && (k1 == n1 || k2 == n2)){
                 if (j > 0)
                   intersection = list2[j - 1];
                 else
                   intersection = list2[j];
                 break;
             }
         }
             if (intersection != -1)
             break;
         
     }
      if(intersection != -1)
     printf("%d",intersection);
     else 
         printf("The two lists do not intersect");
     
     free(list1);
     free(list2);
     return 0;
     }