// editor5
#include<stdio.h>
#include<stdlib.h>
struct Node{
    int data;
    struct Node*prev;
    struct Node*next;
    
};
struct Node*createNode(int data)
{
    struct Node*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 val;
    scanf("%d",&val);
    struct Node*head=createNode(val);
    struct Node*temp=head;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&val);
        struct Node*newNode=createNode(val);
        temp->next=newNode;
        newNode->prev=temp;
        temp=newNode;
    }
    return head;
}
int exists(struct Node*head,int val){
    while(head)
    {
        if(head->data==val)
        return 1;
        head=head->next;
    }
    return 0;
}
        {
        head=tail=newNode;
        }
        else{
            tail->next=newNode;
            newNode->prev=tail;
            tail=newNode;
            
        }
    }
    return head;
    
}

int main()
{
    int n1,n2;
    scanf("%d",&n1);
    if(n1<0)
    {
        printf("Invalid input\n");
        return 0;
    }
    struct Node*head1=builtlist(n1);
    scanf("%d",&n2);
    if(n2<0){
        printf("Invalid input");
        return 0;
    }
    struct Node*head2=builtlist(n2);
    struct Node*temp=head2;
    while(temp){
        if(exists(head1,temp->data))
    {
        printf("%d\n",temp->data);
        return 0;
    }
    temp=temp->next;
    struct Node*temp=head1;
    while(temp&&temp->data!=3)temp=temp->next;
    if(t&&temp)
    {
        t->next=temp;
        temp->pr
    printf("The two lists do not intersect\n");
    return 0;
}