#include <bits/stdc++.h>
using namespace std;
string arr[151];
int first[151];
int last[151];
bool empty[151];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> arr[i];
  int last1 = 0;
  for (int i = 0; i < n; i++) {
    bool k = true;
    first[i] = m - 1;
    last[i] = 0;
    for (int j = 0; j < m; j++) {
      if (k == true && arr[i][j] == 'W') {
        first[i] = j;
        k = false;
      }
      if (arr[i][j] == 'W') {
        last[i] = j;
        last1 = i;
      }
    }
    empty[i] = k;
  }
  int j1 = 0;
  int j2 = 0;
  long long counter = 0;
  int current = 0;
  for (int i = 0; i < n; i++) {
    if (empty[i] == 0 || empty[i + 1] == 0) {
      if (i % 2 == 0) {
        if (i == n - 1 && last1 == n - 1) {
          counter += last[i] - current;
          break;
        }
        int a;
        a = last[i];
        if (empty[i] == true) {
          a = current;
        }
        j2 = max(a, last[i + 1]);
        counter += j2 - current;
        current = j2;
      } else {
        if (i == n - 1 && last1 == n - 1) {
          counter += current - first[i];
          break;
        }
        int a;
        a = first[i];
        if (empty[i] == true) {
          a = current;
        }
        j1 = min(a, first[i + 1]);
        counter += current - j1;
        current = j1;
      }
    }
    if (last1 == i) {
      break;
    }
  }
  cout << counter + last1 << endl;
  return 0;
}
