// Arup Guha
// 3/21/2017
// Solution to 2017 March USACO Bronze Problem: Bovine Genomics

import java.util.*;
import java.io.*;

public class cownomics {

	public static void main(String[] args) throws Exception {

		// Read all the input.
		Scanner stdin = new Scanner(new File("cownomics.in"));
		int n = stdin.nextInt();
		int m = stdin.nextInt();
		String[] spotty = new String[n];
		for (int i=0; i<n; i++) spotty[i] = stdin.next();
		String[] plain = new String[n];
		for (int i=0; i<n; i++) plain[i] = stdin.next();

		// Just count up column by column.
		int res = 0;
		for (int i=0; i<m; i++)
			if (counts(spotty, plain, i))
				res++;

		// Ta da!
		PrintWriter out = new PrintWriter(new FileWriter("cownomics.out"));
		out.println(res);
		out.close();
		stdin.close();
	}

	public static boolean counts(String[] list1, String[] list2, int col) {

		// See which letters are on in the first set of genomes at spot col.
		boolean[] on = new boolean[26];
		for (int i=0; i<list1.length; i++)
			on[list1[i].charAt(col)-'A'] = true;

		// If any of these are also on in the second set, this is a no go.
		for (int i=0; i<list2.length; i++)
			if (on[list2[i].charAt(col)-'A'])
				return false;

		// If we get here, we're good.
		return true;
	}
}