#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops")
using namespace std;
int n, m;
string s[151];
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < m; i++) s[n] += 'G';
  int ans = 0, last = 0;
  for (int i = n - 1; i > -1; i--)
    if (s[i] != s[n]) {
      ans = i;
      break;
    }
  for (int i = 0; i < n; i++) {
    if (s[i] == s[n]) continue;
    int mn = m - 1, mx = 0;
    for (int j = 0; j < m; j++)
      if (s[i][j] == 'W') mn = min(mn, j), mx = max(mx, j);
    if (i & 1) {
      if (last < mx) ans += (mx - last) * 2;
      ans += last - mn;
      last = mn;
    } else {
      if (last > mn) ans += (last - mn) * 2;
      ans += mx - last;
      last = mx;
    }
  }
  cout << ans << '\n';
}
