#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  ;
  int n, m;
  cin >> n >> m;
  char c[n][m];
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < m; j++) {
      c[i][j] = s[j];
    }
  }
  int ans = 0;
  int x = 0, y = 0;
  int k = 0, in = 0;
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) {
      k = 0;
      in = 1;
    } else {
      k = m - 1;
      in = -1;
    }
    for (int j = k; j >= 0 && j < m; j += in) {
      if (c[i][j] == 'W') {
        ans += abs(x - i) + abs(y - j);
        x = i;
        y = j;
      }
    }
  }
  cout << ans << endl;
}
