#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d %d\n", &n, &m);
  char grid[n][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) scanf("%1c", &grid[i][j]);
    scanf("\n");
  }
  int c[n], d[n], last = -1;
  for (int i = 0; i < n; i++) c[i] = -1, d[i] = -1;
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) {
      for (int j = 0; j < m; j++) {
        if (grid[i][j] == 'W') {
          last = i;
          c[i] = j;
        }
      }
      for (int j = m - 1; j >= 0; j--)
        if (grid[i][j] == 'W') d[i] = j;
    } else {
      for (int j = m - 1; j >= 0; j--) {
        if (grid[i][j] == 'W') {
          c[i] = j;
          last = i;
        }
      }
      for (int j = 0; j < m; j++)
        if (grid[i][j] == 'W') d[i] = j;
    }
  }
  int pos = 0, ans = 0;
  for (int i = 0; i <= last; i++) {
    if (i > 0) ans++;
    if (c[i] == -1) continue;
    if (c[i] != d[i]) {
      ans += abs(d[i] - pos);
      pos = d[i];
    }
    ans += abs(c[i] - pos);
    pos = c[i];
  }
  printf("%d\n", ans);
  return 0;
}
