#include <stdlib.h>
#include <stdio.h>

            
int main(int argc, char** argv) {
    int n1, n2;
    scanf("%d", &n1);
    int arr1[n1];
    for(int i=0; i<n1; i++){
        scanf("%d", &arr1[i]);
    }
    
    scanf("%d", &n2);
    int arr2[n2+1];
    for(int i=0; i<n2; i++){
        scanf("%d", &arr2[i]);
    }
    
    for(int i=0; i<n1; i++){
        if (arr1[i]==arr1[i+1]) arr1[i] = -1;
    }
    
    int counter = 0;
    for(int i=0; i<n1; i++){
        arr2[n2+1] = arr1[i]; 
        for(int j=0; j<n2; j++)
            if(arr2[j]==arr2[n2+1]) counter++;
    }
    printf("%d\n", counter);
    return 0;
}

