#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1, N2 = 1e5 + 1, M = 2 * N2,
          SEGN = 2 << (32 - __builtin_clz(N));
char mat[151][151];
int n, m;
set<int> far1, far2;
int solve() {
  int prevc = 0, prevr = 0, ans = 0;
  for (int i = 0; i < n; i++) {
    if (i % 2) {
      for (int j = m - 1; j >= 0; j--)
        if (mat[i][j] == 'W') {
          ans += abs(i - prevr);
          ans += abs(j - prevc);
          prevr = i, prevc = j;
        }
    } else {
      for (int j = 0; j < m; j++)
        if (mat[i][j] == 'W') {
          ans += abs(i - prevr);
          ans += abs(j - prevc);
          prevr = i, prevc = j;
        }
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> mat[i][j];
  cout << solve();
}
