#include <bits/stdc++.h>
using namespace std;
char a[200][200];
int l[200], r[200];
int main() {
  int n, m, sum, total = 0;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    l[i] = -1;
    r[i] = -1;
  }
  for (int i = 0; i < n; i++) {
    sum = 0;
    for (int j = 0; j < m; j++) {
      if (a[i][j] == 'W') r[i] = j;
      if (sum == 0 && a[i][j] == 'W') {
        l[i] = j;
        sum = 1;
      }
    }
  }
  sum = 0;
  int run = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (l[i] != -1) {
      total += i;
      break;
    }
  }
  l[0] = 0;
  if (r[0] == -1) r[0] = 0;
  for (int i = 0; i < n; i++) {
    if (l[i] == -1) {
      if (i % 2 == 0) {
        l[i] = l[i - 1];
        r[i] = l[i - 1];
      } else {
        r[i] = r[i - 1];
        l[i] = r[i - 1];
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (sum == 0) {
      if (i != 0) {
        if (l[i] < l[i - 1]) {
          total += r[i] - 2 * l[i] + l[i - 1];
        } else {
          total += r[i] - l[i - 1];
        }
      } else {
        total += r[i];
      }
      sum = 1;
    } else {
      if (i != 0) {
        if (r[i] < r[i - 1]) {
          total += r[i - 1] - l[i];
        } else {
          total += r[i] * 2 - r[i - 1] - l[i];
        }
      }
      sum = 0;
    }
  }
  cout << total;
}
