#include <bits/stdc++.h>
using namespace std;
char f[150][150];
int a[150], b[150];
int ci = 0, cj = 0, sum = 0;
void moveb(int ni, int nj) {
  sum += nj - cj;
  sum += abs(ni - ci);
  ci = ni;
  cj = nj;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> f[i];
    a[i] = -1;
    b[i] = -1;
  }
  a[0] = 0;
  b[0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (f[i][j] == 'W') {
        if (a[i] == -1) a[i] = j;
        b[i] = j;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == -1) continue;
    if (i % 2) {
      moveb(b[i], i);
      moveb(a[i], i);
    } else {
      moveb(a[i], i);
      moveb(b[i], i);
    }
  }
  cout << sum << endl;
  return 0;
}
