import sys input = lambda :sys.stdin.readline()[:-1] ni = lambda :int(input()) na = lambda :list(map(int,input().split())) yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES") no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO") ####################################################################### c = 0 n,m = na() s = [list(input()) for i in range(n)] a = s[0] b = s[1] for i in range(n): if a[i]!=b[i]: l = i break for i in range(n-1,-1,-1): if a[i]!=b[i]: r = i break x = a[:l]+[b[l]]+a[l:] y = a[:r+1]+[b[r]]+b[r+1:] ans = 1 for i in range(n): t = m+1 for j in range(m): if s[i][j]!=x[j]: t = j break for j in range(t+1,m+1): if s[i][j-1]!=x[j]: ans = 0 if ans: c += 1 ans = 1 for i in range(n): t = m+1 for j in range(m): if s[i][j]!=y[j]: t = j #print(i, j) break for j in range(t+1,m+1): if s[i][j-1]!=y[j]: ans = 0 print(i,t) if ans: c += 1 print(c)