intmain(){ cin >> n >> m; for (int i = 1; i <= n; ++i) { char s[maxm]; scanf("%s", s + 1); for (int j = 1; j <= m; ++j) if (s[j] == 'H') g[i] |= 1 << m - j; } for (int i = 0; i < (1 << m); ++i) { if ((i << 1 & i) || (i << 2 & i)) continue; st[++c1] = i; for (int j = 1; j <= m; ++j) cnt[c1] += i >> j - 1 & 1; } for (int i = 1; i <= c1; ++i) { if (g[1] & st[i]) continue; f[1][i][i] = cnt[i]; } for (int i = 1; i < n; ++i) for (int j = 1; j <= c1; ++j) for (int k = 1; k <= c1; ++k) { if (!f[i][j][k]) continue; for (int o = 1; o <= c1; ++o) { if ((st[j] & st[o]) || (st[k] & st[o]) || (g[i + 1] & st[o])) continue; f[i + 1][o][j] = max(f[i + 1][o][j], f[i][j][k] + cnt[o]); } } int ans = 0; for (int i = 1; i <= n; ++i) for (int j = 1; j <= c1; ++j) for (int k = 1; k <= c1; ++k) ans = max(ans, f[i][j][k]); cout << ans << endl; return0; }