#include <bits/stdc++.h>
using namespace std;
int n, m;
int positive(int n) { return n > 0 ? n : 0; }
int main() {
  while (cin >> n >> m) {
    char glass[n + 2][m + 1];
    int start[n + 2], end[n + 2];
    bool empty[n + 2];
    for (int i = 0; i < n + 2; i++) {
      empty[i] = 1;
      start[i] = m;
      end[i] = -1;
    }
    for (int i = 0; i < n; i++) {
      cin >> glass[i];
      for (int j = 0; j < m; j++) {
        if (glass[i][j] == 'W') {
          if (start[i] == m) {
            empty[i] = 0;
            start[i] = j;
            end[i] = j;
          } else {
            end[i] = j;
          }
        }
      }
    }
    int stop_line = 0, step = max(max(end[0], end[1]), 0);
    for (int i = 1; i < n; i++) {
      if (i % 2 == 1) {
        end[i] = positive(max(end[i], end[i - 1]));
        start[i] = min(end[i], start[i]);
        int tmp = max(0, end[i]) - min(start[i], start[i + 1]);
        step += positive(tmp);
      } else {
        start[i] = min(start[i], start[i - 1]);
        end[i] = max(end[i], start[i]);
        int tmp = max(0, max(end[i], end[i + 1])) - start[i];
        step += positive(tmp);
      }
      if (!empty[i]) {
        stop_line = i;
      }
    }
    step += stop_line;
    cout << step << endl;
  }
}
