#pragma GCC optimize("Ofast")
#pragma GCC target("popcnt")
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
constexpr int mod = 1e8;
int n, m, mp[101];
vector<int> state;
void init() {
for (int i = 0; i < (1 << m); ++i) {
if (i & (i << 1)) continue;
if (i & (i << 2)) continue;
state.push_back(i);
}
}
unordered_map<int, unordered_map<int, int>> dp[101];
//int dp[101][1024][1024];
#define pop_count(x) __builtin_popcount(x)
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
string str;
cin >> str;
for (int j = 0; j < m; ++j) {
mp[i] |= (str[j] == 'H') << j;
}
}
init();
dp[0][0][0] = 0;
for (int i = 1; i <= n; ++i) {
for (int a : state) {
if (a & mp[i]) continue;
for (int b : state) {
if (a & b) continue;
if (b & mp[i - 1]) continue;
for (int c : state) {
if (a & c) continue;
if (b & c) continue;
dp[i][a][b] = max(dp[i][a][b], dp[i - 1][b][c] + pop_count(a));
}
}
}
}
int ans = 0;
for (int a : state) for (int b : state) ans = max(ans, dp[n][a][b]);
cout << ans << endl;
return 0;
}