#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const int N = 151;
int n, m, lastW;
char GRID[N][N];
int DP[N][N][2][N], weed[N];
int calc(int row, int col, bool face, int total) {
  if (row > n) return 0;
  if (DP[row][col][face][total] != -1) return DP[row][col][face][total];
  DP[row][col][face][total] = 40000;
  bool is_weed = (GRID[row][col] == 'W');
  if (!face && (col <= m)) {
    int right =
        calc(row, col + 1, face, total - is_weed) + (col + 1 <= m && col);
    DP[row][col][face][total] = min(DP[row][col][face][total], right);
  } else if (face && col >= 1) {
    int left =
        calc(row, col - 1, face, total - is_weed) + (col - 1 > 0 && col <= m);
    DP[row][col][face][total] = min(DP[row][col][face][total], left);
  }
  if (!(total - is_weed)) {
    int down = calc(row + 1, col, 1 ^ face, weed[row + 1]) + (row + 1 <= n);
    DP[row][col][face][total] = min(DP[row][col][face][total], down);
  }
  return DP[row][col][face][total];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> n >> m;
  lastW = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> GRID[i][j];
      if (GRID[i][j] == 'W') {
        weed[i]++;
        lastW = i;
      }
    }
  }
  n = lastW;
  memset(DP, -1, sizeof DP);
  cout << calc(1, 1, 0, weed[1]);
}
