import sys input = sys.stdin.readline N,M=map(int,input().split()) S=[input().strip() for i in range(N)] for i in range(M): if S[0][i]!=S[1][i]: T1=S[0][:i]+S[1][i]+S[0][i:] T2=S[1][:i]+S[0][i]+S[1][i:] break ANS=0 for i in range(N): s=S[i] ind2=0 c=0 for ind in range(M): if s[ind]==T1[ind2]: ind2+=1 else: c+=1 if s[ind]==T1[ind2+1]: ind2+=2 else: c=100 break if c>=2: break else: ANS+=1 for i in range(N): s=S[i] ind2=0 c=0 for ind in range(M): if s[ind]==T2[ind2]: ind2+=1 else: c+=1 if s[ind]==T2[ind2+1]: ind2+=2 else: c=100 break if c>=2: break else: ANS+=1 print(ANS)