#include <bits/stdc++.h>
using namespace std;
struct dpstate {
  int n, p;
  dpstate(int n = 0, int p = 0) : n(n), p(p) {}
  bool operator<(const dpstate& b) const {
    if (n == b.n) return p > b.p;
    return n < b.n;
  }
  dpstate operator+(const dpstate& b) const {
    return dpstate(n + b.n, p + b.p);
  }
};
char f[151][151];
dpstate dp[151][151];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", f[i]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) dp[i][j] = dpstate(-1, -1);
  dp[0][0] = dpstate(f[0][0] == 'W', 0);
  for (int i = 0; i < n; i++) {
    if (i & 1) {
      for (int j = m - 1; j > 0; j--)
        dp[i][j - 1] =
            max(dp[i][j - 1], dp[i][j] + dpstate(f[i][j - 1] == 'W', 1));
    } else {
      for (int j = 0; j + 1 < m; j++)
        dp[i][j + 1] =
            max(dp[i][j + 1], dp[i][j] + dpstate(f[i][j + 1] == 'W', 1));
    }
    if (i != n - 1) {
      for (int j = 0; j < m; j++)
        dp[i + 1][j] =
            max(dp[i + 1][j], dp[i][j] + dpstate(f[i + 1][j] == 'W', 1));
    }
  }
  dpstate res(0, 0);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) res = max(res, dp[i][j]);
  printf("%d\n", res.p);
  return 0;
}
