#include <bits/stdc++.h>
using namespace std;
const int N = 153;
const int INF = 0x3fffffff;
char s[N][N];
int dp[N][N];
int f[N][N];
int n, m;
int p[N][N];
int main() {
  int i, j, k;
  scanf("%d%d", &n, &m);
  int cnt = 0;
  for (i = 1; i <= n; i++) {
    scanf("%s", s[i] + 1);
    for (j = 1; j <= m; j++) {
      if (s[i][j] == 'W') cnt++;
      p[i][j] = p[i][j - 1] + (s[i][j] == 'W');
    }
  }
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) dp[i][j] = INF;
  for (i = 1; i <= m; i++) {
    dp[1][i] = i - 1;
    f[1][i] = p[1][i];
  }
  for (i = 2; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      for (k = 1; k <= m; k++) {
        int val, add = abs(j - k) + 1;
        if (j <= k) {
          if (i & 1)
            val = p[i][k] - p[i][j - 1];
          else
            val = p[i - 1][k] - p[i - 1][j] + (s[i][k] == 'W');
        } else {
          if (i & 1)
            val = p[i - 1][j - 1] - p[i - 1][k - 1] + (s[i][k] == 'W');
          else
            val = p[i][j] - p[i][k - 1];
        }
        if (f[i][k] < f[i - 1][j] + val) {
          f[i][k] = f[i - 1][j] + val;
          dp[i][k] = dp[i - 1][j] + add;
        }
        if (f[i][k] == f[i - 1][j] + val && dp[i][k] > dp[i - 1][j] + add)
          dp[i][k] = dp[i - 1][j] + add;
      }
    }
  }
  int ans = INF;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++)
      if (f[i][j] == cnt && ans > dp[i][j]) ans = dp[i][j];
  printf("%d\n", ans);
}
