#include using namespace std; int main(){ int N, M; cin >> N >> M; vector S(N); for (int i = 0; i < N; i++){ cin >> S[i]; } int p = 0, q = M - 1; string A; while (p < M){ if (S[0][p] == S[1][p]){ A += S[0][p]; p++; } else { break; } } string B; while (q >= 0){ if (S[0][q] == S[1][q]){ B += S[0][q]; q--; } else { break; } } reverse(B.begin(), B.end()); vector R; if (S[0].substr(p + 1, q - p) == S[1].substr(p, q - p)){ R.push_back(A + S[0][p] + S[0].substr(p + 1, q - p) + S[1][q] + B); } if (S[0].substr(p, q - p) == S[1].substr(p + 1, q - p)){ R.push_back(A + S[1][p] + S[0].substr(p, q - p) + S[0][q] + B); } sort(R.begin(), R.end()); R.erase(unique(R.begin(), R.end()), R.end()); int cnt = R.size(); int ans = 0; for (int i = 0; i < cnt; i++){ bool ok = true; for (int j = 0; j < N; j++){ int p2 = 0; for (int k = 0; k <= M; k++){ if (p2 < M){ if (R[i][k] == S[j][p2]){ p2++; } } } if (p2 != M){ ok = false; } } if (ok){ ans++; } } cout << ans << endl; }