import sys input = lambda: sys.stdin.readline().rstrip() # ----------------------- # n, m = map(int, input().split()) S = [input() for _ in range(n)] ans = 0 s = S[0] t = S[1] j = -1 for i in range(m): if s[i] != t[i]: j = i break T1 = s[:j] + s[j] + t[j:] T2 = s[:j] + t[j] + s[j:] def isok(T, s): i = 0 j = 0 diff = 0 while i < m and j < m+1: if s[i] != T[j]: diff += 1 if diff == 2: break i -= 1 i += 1 j += 1 else: return True return False # T1? for s in S: if not isok(T1, s): break else: ans += 1 # T2? for s in S: if not isok(T2, s): break else: ans += 1 print(ans)