#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const long long maxn = (long long)1e5 + 10;
const int nnn = 664579 + 500;
const int inf = numeric_limits<int>::max() - 1;
const long long INF = 1e18;
long long dx[] = {0, 1, 0, -1};
long long dy[] = {1, 0, -1, 0};
long long dxx[] = {0, 1, 0, -1, 1, 1, -1, -1};
long long dyy[] = {1, 0, -1, 0, 1, -1, 1, -1};
char a[160][160];
void solve() {
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, long long> > p, temp;
  for (int i = 1; i <= (n); i++) {
    temp.clear();
    for (int j = 1; j <= (m); j++) {
      cin >> a[i][j];
      if (a[i][j] == 'W') {
        temp.push_back({i, j});
      }
    }
    if (i % 2 == 0) reverse(temp.begin(), temp.end());
    for (auto u : temp) p.push_back(u);
  }
  long long x = 1, y = 1;
  long long ans = 0;
  for (auto u : p) {
    long long x1 = u.first;
    long long y1 = u.second;
    ans += abs(x1 - x) + abs(y1 - y);
    x = x1;
    y = y1;
  }
  cout << ans;
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long T;
  T = 1;
  long long CT = 0;
  while (T--) {
    solve();
  }
  return 0;
}
