#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  string s[n];
  for (int i = 0; i != n; ++i) cin >> s[i];
  int mn[n], mx[n];
  for (int i = 0; i != n; ++i) {
    mn[i] = INT_MAX;
    mx[i] = INT_MIN;
  }
  int ll = 0;
  for (int i = 0; i != n; ++i)
    for (int j = 0; j != m; ++j)
      if (s[i][j] == 'W') {
        ++ll;
        if (mn[i] == INT_MAX) mn[i] = j;
        mx[i] = j;
      }
  int ans = 0;
  for (int i = 0, lastj = 0, lastdir = 1; i != n && ll; ++i) {
    if (i > 0) ++ans;
    if (lastdir == 1) {
      int target = mx[i];
      if (i + 1 != n) target = max(target, mx[i + 1]);
      target = max(target, lastj);
      for (; lastj <= target; ++lastj) {
        if (lastj < target) ++ans;
        if (s[i][lastj] == 'W') --ll;
      }
      lastj = target;
    } else {
      int target = mn[i];
      if (i + 1 != n) target = min(target, mn[i + 1]);
      target = min(target, lastj);
      for (; lastj >= target; --lastj) {
        if (lastj > target) ++ans;
        if (s[i][lastj] == 'W') --ll;
      }
      lastj = target;
    }
    lastdir *= -1;
  }
  cout << ans << "\n";
  return 0;
}
