def main(): import sys from collections import defaultdict N, M = map(int, sys.stdin.readline().split()) S = [sys.stdin.readline().strip() for _ in range(N)] possible = None for s in S: candidates = defaultdict(int) for i in range(M + 1): for c in 'abcdefghijklmnopqrstuvwxyz': t = s[:i] + c + s[i:] candidates[t] += 1 if possible is None: possible = candidates else: new_possible = defaultdict(int) for t, cnt in possible.items(): if t in candidates: new_possible[t] = cnt + 1 possible = new_possible if not possible: break if possible is None: print(0) else: count = 0 for t, cnt in possible.items(): if cnt == N: count += 1 print(count) if __name__ == "__main__": main()