#include <bits/stdc++.h>
using namespace std;
const bool debug_output = true;
const int maxn = 155;
int n, m, dp[maxn][maxn][2];
char data[maxn][maxn];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> data[i][j];
  memset(dp, 127, sizeof(dp));
  dp[0][0][0] = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      for (int d = 0; d < 2; d++) {
        if (dp[i][j][d] > 1000000000) continue;
        int l = m, r = -1;
        for (int k = 0; k < m; k++)
          if (data[i][k] == 'W') l = min(l, k), r = max(r, k);
        if (r == -1) {
          if (d == 0)
            for (int k = j; k < m; k++)
              dp[i + 1][k][1 - d] =
                  min(dp[i + 1][k][1 - d], dp[i][j][d] + abs(j - k) + 1);
          else
            for (int k = 0; k <= j; k++)
              dp[i + 1][k][1 - d] =
                  min(dp[i + 1][k][1 - d], dp[i][j][d] + abs(j - k) + 1);
          continue;
        }
        if (d == 0) {
          if (j > l) continue;
          for (int k = r; k < m; k++)
            dp[i + 1][k][1 - d] =
                min(dp[i + 1][k][1 - d], dp[i][j][d] + k - j + 1);
        } else {
          if (j < r) continue;
          for (int k = l; k >= 0; k--)
            dp[i + 1][k][1 - d] =
                min(dp[i + 1][k][1 - d], dp[i][j][d] + j - k + 1);
        }
      }
  int answer = 1000000000, nograss = n;
  for (int i = n - 1; i >= 0; i--) {
    int l = m, r = -1;
    for (int k = 0; k < m; k++)
      if (data[i][k] == 'W') l = min(l, k), r = max(r, k);
    if (r == -1)
      nograss--;
    else
      break;
  }
  for (int i = 0; i < m; i++)
    for (int j = 0; j < 2; j++) answer = min(answer, dp[nograss][i][j]);
  cout << max(0, answer - 1);
  return 0;
}
