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