#include <bits/stdc++.h>
using namespace std;
char ara[155][155];
int n, m, dp[155][155][2], Left[155], Right[155], lim;
int func(int row, int col, int face) {
  if (row > lim) return 0;
  if (row == lim) {
    if (!face) {
      if (Left[row] < col) return 1e8;
      if (Right[row] == -1) return 0;
      return (Right[row] - col);
    } else {
      if (Right[row] > col) return 1e8;
      if (Left[row] == 1e9) return 0;
      return (col - Left[row]);
    }
  }
  if (dp[row][col][face] != -1) {
    return dp[row][col][face];
  }
  int ans = 1e9;
  if (!face) {
    int temp;
    temp = Right[row] - col;
    if (Right[row] > col) {
      ans = min(ans, temp + func(row, Right[row], face));
    } else {
      if (col + 1 <= m) ans = min(ans, 1 + func(row, col + 1, face));
      if (row + 1 <= lim && Right[row + 1] <= col)
        ans = min(ans, 1 + func(row + 1, col, 1 - face));
    }
  } else {
    int temp = col - Left[row];
    if (Left[row] < col) {
      ans = min(ans, temp + func(row, Left[row], face));
    } else {
      if (col - 1 >= 1) ans = min(ans, 1 + func(row, col - 1, face));
      if (row + 1 <= lim && Left[row + 1] >= col)
        ans = min(ans, 1 + func(row + 1, col, 1 - face));
    }
  }
  return dp[row][col][face] = ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int i, j;
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      cin >> ara[i][j];
    }
    Left[i] = 1e9;
    Right[i] = -1;
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      if (ara[i][j] == 'W') {
        Left[i] = j;
        lim = i;
        break;
      }
    }
    for (j = m; j >= 1; j--) {
      if (ara[i][j] == 'W') {
        Right[i] = j;
        break;
      }
    }
  }
  memset(dp, -1, sizeof dp);
  int ans = func(1, 1, 0);
  cout << ans << endl;
  return 0;
}
