#include <bits/stdc++.h>
using namespace std;
double eps = 1e-9;
const int INF = 1e9 + 7;
const int MAXN = int(2e5 + 7);
int n, m, ans, a[200][200];
char c[200][200];
void dfs(int x, int y, int dr) {
  if (x == n) return;
  if (dr) {
    int pos = y;
    for (int i = 0; i < m; i++)
      if (c[x][i] == 'W' || c[x + 1][i] == 'W') {
        pos = min(pos, i);
        break;
      }
    ans += y - pos;
    dfs(x + 1, pos, dr ^ 1);
  } else {
    int pos = y;
    for (int i = 0; i < m; i++)
      if (c[x][i] == 'W' || c[x + 1][i] == 'W') pos = max(pos, i);
    ans += pos - y;
    dfs(x + 1, pos, dr ^ 1);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", c[i]);
  dfs(0, 0, 0);
  ans += n - 1;
  for (int i = n - 1; i > 0; i--) {
    bool ok = 1;
    for (int j = 0; j < m; j++)
      if (c[i][j] == 'W') ok = 0;
    if (!ok) break;
    ans--;
  }
  cout << ans << endl;
  return 0;
}
