#include <bits/stdc++.h>
using namespace std;
struct inque {
  long long nom, level;
};
long long n, i, j, ans = 0, mx, x, lv, k, col = 0, m, p, lc, ln;
char c[200][200];
pair<long long, long long> pl[200];
long long cols[200];
long long mymod(long long x) {
  if (x < 0)
    return x * (-1);
  else
    return x;
}
int main() {
  cin >> n >> m;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) cin >> c[i][j];
  for (i = 1; i <= n; i++) {
    pl[i].first = 0;
    pl[i].second = 0;
    for (j = 1; j <= m; j++) {
      if (c[i][j] == 'W') {
        col++;
        cols[i]++;
        if (pl[i].first == 0) pl[i].first = j;
        pl[i].second = j;
      }
    }
  }
  i = 1;
  if (col == 0) {
    cout << 0 << endl;
    return 0;
  }
  pl[1].first = 1;
  if (pl[1].second == 0) pl[1].second = 1;
  i = 1;
  j = 1;
  while (col > 0) {
    while (cols[i] == 0) {
      ans++;
      i++;
    }
    if (i % 2 == 1) {
      if (j > pl[i].first) {
        ans += j - pl[i].first;
        j = pl[i].first;
      }
      ans += pl[i].second - j;
      col -= cols[i];
      cols[i] = 0;
      j = pl[i].second;
    } else {
      if (pl[i].second > j) {
        ans += pl[i].second - j;
        j = pl[i].second;
      }
      ans += j - pl[i].first;
      col -= cols[i];
      cols[i] = 0;
      j = pl[i].first;
    }
  }
  cout << ans << endl;
  return 0;
}
