#include #include #include #include namespace rklib { template bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template bool chmin_non_negative(T &a, const T &b) { if (a < 0 || a > b) { a = b; return true; } return false; } template T div_floor(T a, T b) { if (b < 0) a *= -1, b *= -1; return a >= 0 ? a / b : (a + 1) / b - 1; } template T div_ceil(T a, T b) { if (b < 0) a *= -1, b *= -1; return a > 0 ? (a - 1) / b + 1 : a / b; } } // namespace rklib #define For(i, a, b) for (int i = (int)(a); (i) < (int)(b); ++(i)) #define rFor(i, a, b) for (int i = (int)(a)-1; (i) >= (int)(b); --(i)) #define rep(i, n) For(i, 0, n) #define rrep(i, n) rFor(i, n, 0) #define fi first #define se second using namespace std; using namespace rklib; using lint = long long; using pii = pair; using pll = pair; bool check(string &s, string &t) { int j = 0; rep(i, s.size()) { while (j < int(t.size()) && s[i] != t[j]) ++j; if (j == int(t.size())) return false; ++j; } return true; } int main() { int n, m; cin >> n >> m; string s[n]; rep(i, n) cin >> s[i]; set candidate; int idx = 0; while (s[0][idx] == s[1][idx]) ++idx; candidate = {s[0].substr(0, idx) + s[1][idx] + s[0].substr(idx, m - idx), s[0].substr(0, idx) + s[0][idx] + s[1].substr(idx, m - idx)}; int ans = 0; for (auto t : candidate) { bool flag = true; rep(i, n) if (!check(s[i], t)) { flag = false; break; } if (flag) ++ans; } printf("%d\n", ans); }