#include <bits/stdc++.h>
#pragma comment(linker, "/stack:67108864")
using namespace std;
const long double EPS = 1e-9;
const long double PI = 3.1415926535897932384626433832795;
const long long INF = 1000 * 1000 * 1000;
int main() {
  ifstream ifile("input.txt");
  if (ifile) {
    freopen("input.txt", "rt", stdin);
  }
  if (ifile) {
    freopen("output.txt", "wt", stdout);
  }
  int n, m;
  while (cin >> n >> m) {
    vector<vector<int> > a(n);
    vector<pair<int, int> > ee(n, make_pair(INF, INF));
    ee[0].first = 0;
    ee[0].second = 0;
    for (int i = 0; i < int(n); ++i) {
      for (int j = 0; j < int(m); ++j) {
        char c;
        cin >> c;
        if (c == 'W') {
          a[i].push_back(j);
        }
      }
      if (a[i].size() != 0) {
        ee[i].first = min(ee[i].first, a[i][0]);
        ee[i].second = a[i].back();
        if (i % 2) swap(ee[i].first, ee[i].second);
      }
    }
    while (ee[n - 1].first == INF) n--;
    int way = 0;
    int pos = 0;
    for (int i = 0; i < int(n); ++i) {
      if (a[i].size() > 0) {
        way += abs(ee[i].second - pos);
        pos = ee[i].second;
      }
      if (i < n - 1) {
        if (a[i + 1].size() > 0) {
          way += max(0.0, pow(-1.0, i % 2) * (ee[i + 1].first - pos));
          pos += pow(-1.0, i % 2) *
                 max(0.0, pow(-1.0, i % 2) * (ee[i + 1].first - pos));
        }
      }
      way++;
    }
    way--;
    cout << way << endl;
  }
  return 0;
}
