#include<stdio.h>
#include<stdlib.h>

struct Node {
    int data;
    struct Node*next;
};

struct Node*newNode(int data) {
    struct Node*node=(struct Node*)malloc(sizeof(struct Node));
    node->data = data;
    node->next = NULL;
    return node;
}
struct Node* insertEnd(struct Node*head,int data) {
    if(!head)return newNode(data);
    struct Node*temp=head;
    while(temp->next) temp=temp->next;
    temp->next=newNode(data);
    return head;
}
int getIntersection(struct Node*head1,struct Node*head2) {
    while(head1) {
        struct Node*temp=head2;
        while(temp) {
            if(heap1->data ==temp->data)
            return 
            head1->data;
            temp=temp->next;
        }
        head1=temp->next;
    }
    return-1;
}
int main() {
int n1,n2,val;
scanf("%d",&n1);
if(n1<0) {
    printf("Invalid input\n");
    return 0;
}
struct Node*head1=NULL;
for(int i=0;i<n1;i++){
    scanf("%d",&val);
    head1=insertEnd(head1,val);
    return 0;
}
struct Node*head2=NULL;
for(int i=0;i<n2;i++) {
    scanf("%d",&val);
    head2=insertEnd(head2,val);
}
int intersection = getIntersection(head1,head2);
if(intersection == -1)
printf("The two lists do not intersect\n");
else
printf("%d\n",intersection);
return 0;
}