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