// Arup Guha
// 3/24/2026
// Alternate Solution to Kattis Problem: CD
// https://open.kattis.com/problems/cd
// Used to illustrate BufferedReader and HashSet.

import java.util.*;
import java.io.*;

public class cd2 {

	public static void main(String[] args) throws Exception {
	
		// Get the number of CDs each person has.
		BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer tok  = new StringTokenizer(stdin.readLine());
		int numJack = Integer.parseInt(tok.nextToken());
		int numJill = Integer.parseInt(tok.nextToken());
		
		// Process cases.
		while (numJack != 0 && numJill != 0) {
		
			// Store Jack's CDs here.
			HashSet<Integer> allCDs = new HashSet<Integer>();
			
			// Add all CDs to the one set.
			for (int i=0; i<numJack+numJill; i++) {
				int tmp = Integer.parseInt(stdin.readLine());
				allCDs.add(tmp);
			}
			
			// Using I/E Principle here!
			System.out.println(numJack+numJill-allCDs.size());
			
			// Get next case.
			tok  = new StringTokenizer(stdin.readLine());
			numJack = Integer.parseInt(tok.nextToken());
			numJill = Integer.parseInt(tok.nextToken());
		}
	}
}