// Arup Guha
// 4/13/2026
// TLE solution to Kattis Problem: CD
// Written to prove that Scanner is slower than BufferedReader.

import java.util.*;

public class cdslow {

	public static void main(String[] args) {

		// Get # of each person's CD's.
		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();
		int m = stdin.nextInt();
		
		// Process all cases.
		while (n != 0) {
		
			// Here are Jack's CDs.
			HashSet<Integer> jack = new HashSet<Integer>();
			for (int i=0; i<n; i++) 
				jack.add(stdin.nextInt());
				
			// Now see how many of Jill's are in Jack's list.
			int res = 0;
			for (int i=0; i<m; i++) {
				int x = stdin.nextInt();
				if (jack.contains(x)) {
					res++;
				}
			}
			
			// Output this case.
			System.out.println(res);
		
			// Get next.
			n = stdin.nextInt();
			m = stdin.nextInt();
		}
	}
} 