#include <bits/stdc++.h>
const int N = 155;
using namespace std;
int n;
int m;
int l[N];
int r[N];
int last;
char c[N][N];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> c[i][j];
      if (c[i][j] == 'W') {
        if (l[i] == 0) l[i] = j;
        r[i] = j;
        last = i;
      }
    }
    if (l[i] == 0) l[i] = m + 1;
  }
  l[n + 1] = m + 1;
  int x = 1;
  int ans = 0;
  for (int i = 1; i <= last; i++) {
    if (i % 2) {
      ans += max(0, max(r[i], r[i + 1]) - x) + 1;
      x = max(x, max(r[i], r[i + 1]));
    } else {
      ans += max(0, x - min(l[i], l[i + 1])) + 1;
      x = min(x, min(l[i], l[i + 1]));
    }
  }
  cout << max(0, ans - 1) << endl;
}
