#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int maxn = (int)1e5 + 10;
const int mod = (int)1e9;
int fastMax(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; }
int fastMin(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; }
long int lr[160][160], rl[160][160], dp[160][160][3], m;
int call(int i, int j, int flg, int w) {
  if (w == 0) return 0;
  if (dp[i][j][flg] != -1) return dp[i][j][flg];
  if (flg == 0 && lr[i][j - 1] > 0) return 1001001001;
  if (flg == 1 && rl[i][j + 1] > 0) return 1001001001;
  long mn = 1001001001, p, v, l, k;
  if (flg == 0) {
    p = 0;
    for (k = j; k < m && lr[i][k] < lr[i][m]; k++) p++;
    l = p + 1;
    if (w - lr[i][m] == 0) return p;
    for (; k <= m; k++) {
      v = l + call(i + 1, k, 1, w - lr[i][m]);
      l++;
      mn = (mn < v ? mn : v);
    }
  } else {
    p = 0;
    for (k = j; k > 0 && rl[i][k] < rl[i][1]; k--) p++;
    l = p + 1;
    if (w - rl[i][1] == 0) return p;
    for (; k > 0; k--) {
      v = l + call(i + 1, k, 0, w - rl[i][1]);
      l++;
      mn = (mn < v ? mn : v);
    }
  }
  dp[i][j][flg] = mn;
  return mn;
}
int main() {
  int w = 0, n, i, j;
  memset(dp, -1, sizeof(dp));
  string str;
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> str;
    for (j = 1; j <= m; j++)
      if (str[j - 1] == 'W')
        lr[i][j] = lr[i][j - 1] + 1;
      else
        lr[i][j] = lr[i][j - 1];
    for (j = m; j > 0; j--)
      if (str[j - 1] == 'W')
        rl[i][j] = rl[i][j + 1] + 1;
      else
        rl[i][j] = rl[i][j + 1];
    w = w + lr[i][m];
  }
  w = call(1, 1, 0, w);
  cout << w << endl;
  return 0;
}
