#include <bits/stdc++.h>
using namespace std;
int main() {
  int ret = 0;
  int h, w;
  cin >> h >> w;
  vector<vector<char> > grid(h);
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      char c;
      cin >> c;
      grid[i].push_back(c);
    }
  int xPos = 0;
  int yPos = 0;
  int lastX = 0;
  int lastY = 0;
  int possX;
  int testDir;
  if (h % 2 != 0) {
    possX = w - 1;
    testDir = -1;
  } else {
    possX = 0;
    testDir = 1;
  }
  int possY = h - 1;
  if (!(h == 1 && w == 1)) {
    while (grid[possY][possX] != 'W') {
      if (possX + testDir < 0 || possX + testDir >= w) {
        possY--;
        testDir = -testDir;
      } else {
        possX += testDir;
      }
      if (possX == 0 && possY == 0) break;
    }
  }
  lastX = possX;
  lastY = possY;
  int dir = 1;
  while (xPos != lastX || yPos != lastY) {
    bool canMoveDown = true;
    for (int i = xPos + dir; i >= 0 && i < w; i += dir) {
      if (grid[yPos][i] == 'W') {
        canMoveDown = false;
        break;
      }
    }
    if (canMoveDown && yPos < h - 1) {
      for (int i = xPos + dir; i >= 0 && i < w; i += dir) {
        if (grid[yPos + 1][i] == 'W') {
          canMoveDown = false;
          break;
        }
      }
    }
    if (canMoveDown) {
      dir = -dir;
      yPos++;
    } else {
      if (xPos + dir < 0 || xPos + dir >= w) {
        dir = -dir;
        yPos++;
      } else
        xPos += dir;
    }
    ret++;
  }
  cout << ret << endl;
  return 0;
}
