#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int MAXN = 151;
int n, m;
char g[MAXN][MAXN];
long long dp[MAXN][MAXN];
int num[MAXN][MAXN];
int q = 0;
bool IsGood(int x, int y, int cnt) { return cnt == num[x][y]; }
bool IsInBorder(int x, int y) { return x >= 0 && y >= 0 && x < n && y < m; }
long long F(int x, int y, int cnt) {
  if (!IsInBorder(x, y)) return INF;
  if (g[x][y] == 'W') ++cnt;
  if (!IsGood(x, y, cnt)) return INF;
  if (cnt == q) {
    return 0;
  }
  if (dp[x][y] >= INF) {
    int dy = (x & 1 ? -1 : 1);
    dp[x][y] = 1 + min(F(x + 1, y, cnt), F(x, y + dy, cnt));
  }
  return dp[x][y];
}
int main() {
  cin >> n >> m;
  for (int(i) = 0; (i) < (n); ++(i)) {
    for (int(j) = 0; (j) < (m); ++(j)) {
      dp[i][j] = INF;
      cin >> g[i][j];
      if (g[i][j] == 'W') ++num[i][j];
    }
  }
  for (int(i) = 0; (i) < (n); ++(i)) {
    if (i & 1) {
      if (i) num[i][m - 1] += num[i - 1][m - 1];
      for (int(j) = (m - 1) - 1; (j) >= 0; --(j)) {
        num[i][j] += num[i][j + 1];
      }
    } else {
      if (i) num[i][0] += num[i - 1][0];
      for (int j = 1; j < m; ++j) {
        num[i][j] += num[i][j - 1];
      }
    }
  }
  for (int(i) = 0; (i) < (n); ++(i)) {
    for (int(j) = 0; (j) < (m); ++(j)) {
      q = max(q, num[i][j]);
    }
  }
  cout << F(0, 0, 0) << endl;
  return 0;
}
