#include <bits/stdc++.h>
using namespace std;
char a[1001][1001];
int main() {
  int n, m, sum = 0;
  cin >> n >> m;
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (m); j++) cin >> a[i][j];
  int n1 = 1;
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (m); j++)
      if (a[i][j] == 'W') n1 = i + 1;
  n = n1;
  int x = 0, y = 0, t = 1;
  while (x < n) {
    int q = -1;
    if (t) {
      for (int i = (y); i <= (m - 1); i++) {
        if (a[x][i] == 'W') q = i;
        if (x < n - 1)
          if (a[x + 1][i] == 'W') q = i;
      }
      if (q != -1) sum += q - y;
      t = 0;
    } else {
      for (int i = (y); i >= (0); i--) {
        if (a[x][i] == 'W') q = i;
        if (x < n - 1)
          if (a[x + 1][i] == 'W') q = i;
      }
      if (q != -1) sum += y - q;
      t = 1;
    }
    if (q != -1) y = q;
    ++x;
    ++sum;
  }
  cout << sum - 1;
  return 0;
}
