// Arup Guha
// 3/21/2017
// Solution to 2017 March USACO Silver Problem: Bovine Genomics

import java.util.*;
import java.io.*;

public class cownomics_silver {

	public static int[] code;

	public static void main(String[] args) throws Exception {

		// Easy look up...
		code = new int[26];
		code['A'-'A'] = 0;
		code['C'-'A'] = 1;
		code['G'-'A'] = 2;
		code['T'-'A'] = 3;

		// 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++)
			for (int j=i+1; j<m; j++)
				for (int k=j+1; k<m; k++)
					if (counts(spotty, plain, i, j, k))
						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 c1, int c2, int c3) {

		// See which triplets of letters show up in the first set.
		boolean[] on = new boolean[64];
		for (int i=0; i<list1.length; i++)
			on[16*code[list1[i].charAt(c1)-'A']+4*code[list1[i].charAt(c2)-'A']+code[list1[i].charAt(c3)-'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[16*code[list2[i].charAt(c1)-'A']+4*code[list2[i].charAt(c2)-'A']+code[list2[i].charAt(c3)-'A']])
				return false;

		// If we get here, we're good.
		return true;
	}
}