def main(): N, M = map(int, input().split()) S = [input() for i in range(N)] def subseq(s, x): p = 0 for c in s: if p < len(x) and x[p] == c: p += 1 return p == len(x) def check(x): for s in S: if not subseq(x, s): return False return True for i in range(M): for j in range(N): if S[0][i] != S[j][i]: ans = 0 ans += check(S[0][:i] + S[0][i] + S[j][i:]) ans += check(S[j][:i] + S[j][i] + S[0][i:]) print(ans) return if __name__ == '__main__': main()