#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > Sh;
const int tmax = 155;
char table[tmax][tmax];
pair<int, int> mow[tmax];
pair<int, int> ccount(int row, int side, int ai) {
  if (mow[row].second == 0 && mow[row + 1].second == 0) return make_pair(0, ai);
  if (mow[row].second == 0) {
    if (side == 0 && ai < mow[row + 1].second)
      return make_pair(mow[row + 1].second - ai, mow[row + 1].second);
    else if (side == 1 && ai >= mow[row + 1].first)
      return make_pair(ai - mow[row + 1].first, mow[row + 1].first);
    else
      return make_pair(0, ai);
  }
  if (mow[row + 1].second == 0) {
    if (side == 0)
      return make_pair(mow[row].second - ai, mow[row].second);
    else
      return make_pair(ai - mow[row].first, mow[row].first);
  }
  if (side == 0)
    return make_pair(max(mow[row + 1].second, mow[row].second) - ai,
                     max(mow[row + 1].second, mow[row].second));
  else
    return make_pair(ai - min(mow[row + 1].first, mow[row].first),
                     min(mow[row + 1].first, mow[row].first));
}
int main() {
  int N, M;
  scanf("%d %d", &N, &M);
  for (int i = 0; i < tmax; i++) mow[i].first = 1 << 30, mow[i].second = 0;
  int last = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      scanf(" %c", &table[i][j]);
      if (table[i][j] == 'W') {
        mow[i].first = min(j, mow[i].first);
        mow[i].second = max(j, mow[i].second);
        last = max(last, i);
      }
    }
  }
  int side = 0, howmany = 0;
  int ai = 1;
  for (int i = 1; i < N; i++) {
    pair<int, int> ret = ccount(i, side, ai);
    howmany += ret.first;
    ai = ret.second;
    side ^= 1;
  }
  if (mow[N].second) {
    if (side)
      howmany += ai - mow[N].first;
    else
      howmany += mow[N].second - ai;
  }
  printf("%d\n", max(howmany + last - 1, 0));
  return 0;
}
