#include <bits/stdc++.h>
using namespace std;
int block = 400;
const long double eps = 1e-7;
const long long pe = 137;
const long long pe2 = 1181;
const long long N = 1e4 + 200;
const long long mod = 1e9 + 7;
const long long mod2 = 1e9 + 9;
const long long INF = 1e16;
int n, m;
char a[200][200];
int dp[200][200], h[200], lrow;
int fos[200], lpos[200];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    int st = 0, last = m + 1, c = 0;
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
      dp[i][j] = 1e9;
      if (a[i][j] == 'W') {
        last = j;
        if (st == 0) st = j;
        c++;
      }
    }
    if (i % 2 == 0) swap(last, st);
    fos[i] = st;
    lpos[i] = last;
    if (c > 0) lrow = i;
    h[i] = h[i - 1] + c;
    if (i % 2) {
      if (fos[i] == 0) fos[i] = m + 1;
      if (lpos[i] == m + 1) lpos[i] = 0;
    } else {
      if (fos[i] == m + 1) fos[i] = 0;
      if (lpos[i] == 0) lpos[i] = m + 1;
    }
  }
  dp[1][1] = 0;
  for (int i = 1; i <= n; i++) {
    if (i % 2) {
      for (int j = 1; j <= m; j++) {
        if (dp[i][j] != 1e9) {
          for (int k = 1; k <= m; k++) {
            if (j + k >= lpos[i] && j + k <= m) {
              dp[i][j + k] = min(dp[i][j + k], dp[i][j] + k);
            }
          }
          if (j >= lpos[i] || h[i] - h[i - 1] == 0) {
            if (fos[i + 1] <= j) {
              dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1);
            }
          }
        }
      }
    } else {
      for (int j = m; j >= 1; j--) {
        if (dp[i][j] != 1e9) {
          for (int k = 1; k <= m; k++) {
            if (j - k >= 1 && j - k <= lpos[i]) {
              dp[i][j - k] = min(dp[i][j - k], dp[i][j] + k);
            }
          }
          if (j <= lpos[i] || h[i] - h[i - 1] == 0) {
            if (fos[i + 1] >= j) {
              dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1);
            }
          }
        }
      }
    }
  }
  int ans = 1e9;
  if (lrow % 2) {
    for (int i = lpos[lrow]; i <= m; i++) {
      ans = min(ans, dp[lrow][i]);
    }
  } else {
    for (int i = 1; i <= lpos[lrow]; i++) {
      ans = min(ans, dp[lrow][i]);
    }
  }
  if (ans == 1e9) ans = 0;
  cout << ans;
}
