#include <bits/stdc++.h>
using namespace std;
const int maxn = 150;
char dat[maxn][maxn];
int bound[maxn + 1][2];
void calcbound(int n, int m) {
  for (int i = 0; i < n; i++) {
    bound[i][0] = 0;
    while (bound[i][0] < m && dat[i][bound[i][0]] != 'W') bound[i][0]++;
    bound[i][1] = m - 1;
    while (bound[i][1] >= 0 && dat[i][bound[i][1]] != 'W') bound[i][1]--;
  }
  bound[n][0] = m;
  bound[n][1] = -1;
}
int mincount(int n, int m) {
  int ans = 0;
  int move, now = 0;
  int temp;
  for (int i = 0; i < n; i++) {
    if (i % 2) {
      temp = now - min(bound[i][0], bound[i + 1][0]);
      if (temp >= 0) {
        ans += temp;
        now = min(bound[i][0], bound[i + 1][0]);
      }
    } else {
      temp = max(bound[i][1], bound[i + 1][1]) - now;
      if (temp >= 0) {
        ans += temp;
        now = max(bound[i][1], bound[i + 1][1]);
      }
    }
    if (i > 0) ans++;
  }
  for (int i = n - 1; i > 0; i--) {
    if (bound[i][0] > bound[i][1])
      ans--;
    else
      break;
  }
  return ans;
}
int main() {
  int n, m;
  cin >> n >> m;
  int i, j;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) cin >> dat[i][j];
    cin.get();
  }
  calcbound(n, m);
  cout << mincount(n, m) << endl;
  return 0;
}
