#include<stdio.h>

int main(void){
	
	int n,S[3],q,T[2],C=0;
	scanf("%d",&n);
	scanf("%d %d %d",&S[0],&S[1],&S[2]);
	scanf("%d",&q);
	scanf("%d %d %d",&T[0],&T[1]);
	
	for(int i=0,i<3,i++){
		
		if (S[i]==T[1]) C++;
		if (S[i]==T[2]) C++;
		
	}
	printf("%d",C);
	
return 0 ;}