local n, m = io.read("*n", "*n", "*l") local s = {} for i = 1, n do s[i] = io.read() end local function check(w) for i = 1, n do local skipped = false local si = s[i] for j = 1, m + 1 do local z = skipped and si:byte(j - 1) or si:byte(j) if w:byte(j) ~= z then if skipped then return false else skipped = true end end end end return true end local c = 0 if n == 2 then for i = 1, m do if s[1]:byte(i) ~= s[2]:byte(i) then local w = s[1]:sub(1, i) .. s[2]:sub(i, m) if check(w) then c = c + 1 end w = s[2]:sub(1, i) .. s[1]:sub(i, m) if check(w) then c = c + 1 end break end end else for i = 1, m do local t = {} local z = 0 for j = 1, n do local b = s[j]:byte(i) if not t[b] then z = z + 1 t[b] = {j} else table.insert(t[b], 0) end end if 2 < z then break end if z == 2 then local k1, v1 = next(t) local k2, v2 = next(t, k1) if #v1 == 1 then local w = s[k2]:sub(1, i) .. s[k1]:sub(i, m) if check(w) then c = c + 1 end else local w = s[k1]:sub(1, i) .. s[k2]:sub(i, m) if check(w) then c = c + 1 end end break end end end print(c)