#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
  int n, m;
  cin >> n >> m;
  string s[n];
  for (int i = 0; i < n; i++) cin >> s[i];
  int last = 0;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int temp = last;
    if (i % 2 == 0) {
      for (int j = 0; j < m; j++) {
        if (s[i][j] == 'W' || (i + 1 < n && s[i + 1][j] == 'W')) {
          temp = j;
        }
      }
    } else {
      for (int j = m - 1; j >= 0; j--) {
        if (s[i][j] == 'W' || (i + 1 < n && s[i + 1][j] == 'W')) {
          temp = j;
        }
      }
    }
    ans += abs(temp - last);
    last = temp;
  }
  int extra = 0;
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] == 'W') {
        extra = i;
        break;
      }
    }
    if (extra) break;
  }
  ans += extra;
  cout << ans << endl;
}
