#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1E9;
const long long LINF = (long long)1E18;
const long double PI = acos(-1.0);
const long double EPS = 1E-7;
template <typename T>
T gcd(T a, T b) {
  return (b == 0) ? abs(a) : gcd(b, a % b);
}
template <typename T>
inline T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <typename T>
inline T mod(T a, T b) {
  a %= b;
  if (a < 0) a += b;
  return a;
}
template <typename T>
inline T sqr(T x) {
  return x * x;
}
template <typename T>
inline T gmax(T a, T b) {
  return (a > b ? a : b);
}
template <typename T>
inline T gmin(T a, T b) {
  return (a < b ? a : b);
}
template <typename T>
inline string toString(T x) {
  ostringstream oss;
  oss << x;
  return oss.str();
}
inline long long toInt(const string& st) {
  istringstream iss(st);
  long long x;
  iss >> x;
  return x;
}
inline long double toDouble(const string& st) {
  istringstream iss(st);
  long double x;
  iss >> x;
  return x;
}
inline string toLower(string st) {
  for (int i = 0; i < (((int)(st).size())); i++) st[i] = tolower(st[i]);
  return st;
}
inline string toUpper(string st) {
  for (int i = 0; i < (((int)(st).size())); i++) st[i] = toupper(st[i]);
  return st;
}
bool LOCAL = false, OUTPUT = true;
const char DEBUG_PARAM[] = "__LOCAL_TESTING";
const char IN[] = "_.in";
const char OUT[] = "_.out";
inline void init();
inline void run();
int ntest = 0, test;
int main(int argc, char* argv[]) {
  if (argc > 1 && strcmp(argv[1], DEBUG_PARAM) == 0) {
    LOCAL = true;
    freopen(IN, "r", stdin);
  }
  init();
  if (ntest == 0) {
    cerr << "ntest = ?" << endl;
    return 0;
  }
  for (test = 1; test <= ntest; ++test) {
    run();
  }
  return 0;
}
inline void stop() { ntest = test - 1; }
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
inline void init() {
  OUTPUT = true;
  ntest = 1;
}
int m, n, f[250][250];
char a[250][250];
inline void run() {
  cin >> m >> n;
  for (int i = 0; i < (m); i++)
    for (int j = 0; j < (n); j++) cin >> a[i][j];
  for (int i = 0; i < (m + 1); i++)
    for (int j = 0; j < (n); j++) f[i][j] = INF;
  f[0][0] = 0;
  for (int i = 0; i < (m); i++) {
    if (i % 2 == 0) {
      for (int j = 0; j < (n); j++)
        for (int k = (n - 1); k >= (0); k--) {
          f[i + 1][k] = min(f[i + 1][k], f[i][j] + abs(j - k) + 1);
          if (j == k) break;
          if (a[i][k] == 'W' || a[i + 1][k] == 'W') break;
        }
    } else {
      for (int j = 0; j < (n); j++)
        for (int k = 0; k < (n); k++) {
          f[i + 1][k] = min(f[i + 1][k], f[i][j] + abs(j - k) + 1);
          if (j == k) break;
          if (a[i][k] == 'W' || a[i + 1][k] == 'W') break;
        }
    }
  }
  int ret = INF;
  for (int i = (m); i >= (0); i--) {
    int l = 0;
    for (int j = 0; j < (n); j++)
      if (a[i][j] == 'W') l = 1;
    if (l == 1) break;
    if (i == 0) {
      cout << 0;
      return;
    }
    for (int j = 0; j < (n); j++) ret = min(ret, f[i][j] - 1);
  }
  cout << ret;
}
