#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int l[200], r[200];
  for (int i = 0; i < n; i++) {
    l[i] = 250;
    r[i] = -1;
  }
  l[0] = 0;
  r[0] = 0;
  string s, W("W");
  for (int i = 0; i < n; i++) {
    cin >> s;
    for (int j = 0; j < m; j++)
      if (s[j] == W[0]) {
        l[i] = min(l[i], j);
        r[i] = max(r[i], j);
      }
  }
  for (int i = n - 1; i > 0; i--) {
    if (l[i] != 250)
      if (i % 2 == 0) {
        l[i - 1] = min(l[i], l[i - 1]);
        r[i - 1] = max(l[i - 1], r[i - 1]);
        l[i] = l[i - 1];
      } else {
        r[i - 1] = max(r[i], r[i - 1]);
        l[i - 1] = min(l[i - 1], r[i - 1]);
        r[i] = r[i - 1];
      }
  }
  int ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (r[i] != -1) {
      ans += r[i] - l[i] + 1;
    }
  }
  ans--;
  cout << ans << endl;
  return 0;
}
