#include <bits/stdc++.h>
using namespace std;
constexpr auto MAX = 156;
char s[MAX][MAX];
int n, m;
int moveto(int r, int c, bool right, int carry) {
  for (int j = right ? m : 1; right ? j > c : j < c; right ? j-- : j++)
    if (s[r][j] == 'W') return carry + abs(j - c) + moveto(r, j, right, 0);
  if (r == n) return 0;
  for (int j = right ? m : 1; right ? j > 0 : j <= m; right ? j-- : j++)
    if (s[r + 1][j] == 'W')
      return carry + 1 + abs(j - c) + moveto(r + 1, j, !right, 0);
  return moveto(r + 1, c, !right, carry + 1);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; scanf("%s", (s[i] + 1)) && i <= n; i++)
    ;
  printf("%d\n", moveto(1, 1, true, 0));
  return 0;
}
