#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  char str[155][155];
  int i, j;
  for (i = 0; i < n; i++) {
    cin >> str[i];
  }
  int ans = 0, x = 0, y = 0;
  for (i = 0; i < n; i++) {
    if (i % 2 == 0) {
      for (j = 0; j < m; j++) {
        if (str[i][j] == 'W') {
          ans += abs(x - i) + abs(y - j);
          x = i;
          y = j;
        }
      }
    } else {
      for (j = m - 1; j >= 0; j--) {
        if (str[i][j] == 'W') {
          ans += abs(x - i) + abs(y - j);
          x = i;
          y = j;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
