#include #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using pii = pair; using ll = long long; int main() { int n, m; cin >> n >> m; vector s(n); rep(i, n) cin >> s[i]; string t, u; rep(i, m) { if (s[0][i] != s[1][i]) { t = s[0].substr(0, i) + s[0][i] + s[1].substr(i); u = s[1].substr(0, i) + s[1][i] + s[0].substr(i); break; } } int ok1 = 1, ok2 = 1; rep(i, n) { int si = 0, ti = 0; while (ti < m + 1) { if (s[i][si] == t[ti]) si++; ti++; } if (si != m) ok1 = 0; si = 0; rep(ui, m + 1) { if (s[i][si] == u[ui]) si++; } if (si != m) ok2 = 0; } int ans = ok1 + ok2; cout << ans << endl; return 0; }