#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, now, count, j, row, col, left, right;
  scanf("%d %d", &row, &col);
  char arr[row][col];
  for (i = 0; i < row; i++) {
    scanf("%s", &arr[i]);
  }
  pair<int, int> track[row];
  count = 0;
  for (i = 0; i < row; i++) {
    left = 0;
    right = col - 1;
    while ((left < col)) {
      if (arr[i][left] == 'W') break;
      ++left;
    }
    while ((right >= 0)) {
      if (arr[i][right] == 'W') break;
      --right;
    }
    track[i].first = left;
    track[i].second = right;
  }
  for (i = row - 1; i >= 0; i--) {
    for (j = 0; j < col; j++)
      if (arr[i][j] == 'W') break;
    if (arr[i][j] == 'W') {
      row = i;
      break;
    }
  }
  now = 0;
  if (i != -1) {
    for (i = 0; i < row; i++) {
      if ((i % 2) == 0) {
        if ((track[i].second != -1) || (track[i + 1].second != -1)) {
          if (now < (max(track[i].second, track[i + 1].second))) {
            count += (max(track[i].second, track[i + 1].second)) - now;
            now = max(track[i].second, track[i + 1].second);
          }
        }
      } else {
        if ((track[i].first != col) || (track[i + 1].first != col)) {
          if (now > (min(track[i].first, track[i + 1].first))) {
            count += now - (min(track[i].first, track[i + 1].first));
            now = min(track[i].first, track[i + 1].first);
          }
        }
      }
      ++count;
    }
    if ((row % 2) == 0)
      count += track[row].second - now;
    else
      count += now - track[row].first;
  }
  printf("%d\n", count);
  return 0;
}
