// Arup Guha
// 1/10/2022
// Solution to COP 3503 Recitation Program #1: CD

import java.util.*;
import java.io.*;

public class cd {

	public static void main(String[] args) throws Exception {
	
		BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer tok = new StringTokenizer(stdin.readLine());
		int nJack = Integer.parseInt(tok.nextToken());
		int nJill = Integer.parseInt(tok.nextToken());
		
		// Process multiple cases.
		while (nJack != 0) {
		
			// Read in all of Jack's CDs.
			HashSet<Integer> jack = new HashSet<Integer>();
			for (int i=0; i<nJack; i++)
				jack.add(Integer.parseInt(stdin.readLine()));
			
			// As we read in Jill's add it to our count if Jack has it.
			int res = 0;
			for (int i=0; i<nJill; i++) 
				if (jack.contains(Integer.parseInt(stdin.readLine())))
					res++;
			
			// Ta da!
			System.out.println(res);
			
			// Get next case.
			tok = new StringTokenizer(stdin.readLine());
			nJack = Integer.parseInt(tok.nextToken());
			nJill = Integer.parseInt(tok.nextToken());
		}
	}
}