#include <bits/stdc++.h>
using namespace std;
int n, m;
int k;
bool debug = false;
char mp[170][170];
int l[170], r[170];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    scanf("%s", mp[i]);
    l[i] = m;
    r[i] = -1;
    for (int j = 0; j < m; j++)
      if (mp[i][j] == 'W') {
        l[i] = j;
        break;
      }
    for (int j = m - 1; j >= 0; j--)
      if (mp[i][j] == 'W') {
        r[i] = j;
        break;
      }
  }
  int ans = 0, pos = 0, dir = 1;
  for (int i = 0, j = 1; i < n; i = j) {
    j = i + 1;
    while (j < n && r[j] == -1) j++;
    if (r[i] != -1) {
      if (dir == 1) {
        ans += r[i] - pos;
        pos = r[i];
      } else {
        ans += pos - l[i];
        pos = l[i];
      }
    }
    if (j == n)
      break;
    else {
      dir = (j - i) % 2 == 1 ? 1 - dir : dir;
      int npos;
      if (dir == 1) {
        npos = min(l[j], pos);
      } else {
        npos = max(r[j], pos);
      }
      ans += abs(npos - pos);
      pos = npos;
      ans += (j - i);
    }
  }
  cout << ans << endl;
  return 0;
}
