// editor5
# include<stdio.h>
#include<stdio.h>
struct Node{
    int data;
    struct Node*prev;
    struct Node*next;
    
};
struct Node*createNode(int data)
{
    structNode*newNode=(struct Node*)malloc(sizeof(struct Node));
    newNode->data=data;
    newNode->prev=newNode->next=NULL;
    return newNode;
    
}
struct Node*builtlist(int n)
{
    if(n<=0)
    return NULL;
    int data;
    struct Node*head=NULL,*tail=NULL;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&data);
        struct Node*newNode=createNode(data);
        if(!head)
        {
        head=tail=newNode;
        }
        else{
            tail->next=newNode;
            newNode->prev=tail;
            tail=newNode;
            
        }
    }
    return head;
    
}
int find(struct Node*head1,struct Node*head2)
{
    struct Node*p1=head1;
    while(p1)
    {
        struct Node*p2=head2;
        while(p2)
        {
            if(p1->data==p2->data)
            {
                return p1->data;
            }
            p2=p2->next;
        }
        p1=p1->next;
    }
    return-1;
}
int main()
{
    int n1,n2;
    scanf("%d",&n1);
    if(n1<0)
    {
        printf("Invalid input\n");
        return 0;
    }
    struct Node*head1=buildlist(n2);
    int inter=find(head1,head2);
    if(inter!=-1)
    print("%d\n",inter);
    else
    printf("The two lists do not intersect\n");
    return 0;
}