#include <bits/stdc++.h>
using namespace std;
void fast() {
  cin.tie(0);
  cin.sync_with_stdio(0);
}
int n, m, dp[155][155][155];
char arr[155][155];
int total = 0;
vector<pair<int, int>> num(155);
int main() {
  fast();
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> arr[i][j];
      total += (arr[i][j] == 'W');
    }
  }
  for (int k = 0; k < n; ++k) {
    bool b = false;
    num[k].first = -1;
    num[k].second = -1;
    int last = -1;
    for (int i = 0; i < m; ++i) {
      if (arr[k][i] == 'W' && !b)
        num[k].first = i, b = true;
      else if (arr[k][i] == 'W')
        last = i;
    }
    num[k].second = last;
  }
  num[n].first = -1;
  bool a = 0;
  int j = 0;
  int cnt = 0;
  int first = 0, last = 0;
  for (int l = 0; l < n; ++l) {
    if (a)
      j = m - 1;
    else
      j = 0;
    while (j >= 0 && j < m) {
      if (arr[l][j] == 'W') {
        cnt += abs(l - first) + abs(j - last);
        first = l;
        last = j;
      }
      if (a)
        j--;
      else
        j++;
    }
    a = !a;
  }
  cout << cnt;
}
