#include <bits/stdc++.h>
using namespace std;
int main() {
  string lawn[151];
  int n, m;
  int l[151], r[151];
  cin >> n >> m;
  int last = 0;
  for (int i = 0; i < n; i++) {
    cin >> lawn[i];
    l[i] = r[i] = -1;
    for (int j = 0; j < m; j++) {
      if (lawn[i][j] == 'W') {
        l[i] = j;
        break;
      }
    }
    for (int j = m - 1; j >= 0; j--) {
      if (lawn[i][j] == 'W') {
        r[i] = j;
        break;
      }
    }
    if (l[i] != -1) last = i;
  }
  n = last + 1;
  int cur = 0, ans = 0, des;
  for (int i = 0; i < n - 1; i++) {
    if (i % 2 == 0) {
      des = max(r[i], r[i + 1]);
      des = max(des, cur);
      if (r[i] == -1 && r[i + 1] == -1) des = cur;
      ans += (des - cur);
      ans++;
    } else {
      if (l[i] == -1 || l[i + 1] == -1)
        des = max(l[i], l[i + 1]);
      else
        des = min(l[i], l[i + 1]);
      if (des == -1) des = cur;
      des = min(des, cur);
      ans += (cur - des);
      ans++;
    }
    cur = des;
  }
  if (n >= 0) {
    if ((n - 1) % 2 == 0) {
      if (r[n - 1] != -1) {
        ans += (r[n - 1] - cur);
      } else if (n > 1)
        ans--;
    } else {
      if (l[n - 1] != -1) {
        ans += (cur - l[n - 1]);
      } else if (n > 1)
        ans--;
    }
  }
  cout << ans << endl;
  return 0;
}
