#include <bits/stdc++.h>
using namespace std;
const int N = 150;
const int MAXINT = 65536;
int n, m, i, j, f[N][N][2];
string s[N];
int main() {
  cin >> n >> m;
  for (i = 0; i < n; i++) cin >> s[i];
  f[0][0][0] = MAXINT;
  f[0][0][1] = 0;
  for (i = 1; i < m; i++) {
    f[0][i][0] = MAXINT;
    f[0][i][1] = f[0][i - 1][1] + 1;
  }
  for (i = 1; i < n; i++) {
    bool flag = true;
    if (f[i - 1][0][0] != MAXINT)
      f[i][0][1] = f[i - 1][0][0] + 1;
    else
      f[i][0][1] = MAXINT;
    if (s[i - 1][0] == 'W' || s[i][0] == 'W') flag = false;
    for (j = 1; j < m; j++) {
      f[i][j][1] = f[i][j - 1][1] + 1;
      if (flag && f[i - 1][j][0] + 1 < f[i][j][1])
        f[i][j][1] = f[i - 1][j][0] + 1;
      if (s[i - 1][j] == 'W' || s[i][j] == 'W') {
        flag = false;
      }
    }
    flag = true;
    if (f[i - 1][m - 1][1] != MAXINT)
      f[i][m - 1][0] = f[i - 1][m - 1][1] + 1;
    else
      f[i][m - 1][0] = MAXINT;
    if (s[i - 1][m - 1] == 'W' || s[i][m - 1] == 'W') flag = false;
    for (j = m - 2; j >= 0; j--) {
      f[i][j][0] = f[i][j + 1][0] + 1;
      if (flag && f[i - 1][j][1] + 1 < f[i][j][0])
        f[i][j][0] = f[i - 1][j][1] + 1;
      if (s[i - 1][j] == 'W' || s[i][j] == 'W') {
        flag = false;
      }
    }
  }
  int k = -1;
  for (i = n - 1; i >= 0; i--) {
    bool flag = false;
    for (j = 0; j < m; j++)
      if (s[i][j] == 'W') {
        flag = true;
        break;
      }
    if (flag) {
      k = i;
      break;
    }
  }
  if (k == -1) {
    cout << 0 << endl;
    return 0;
  }
  int ans = 0;
  for (i = 0; i < m; i++) {
    if (s[k][i] == 'W') {
      ans = f[k][i][0];
      break;
    }
  }
  for (i = m - 1; i >= 0; i--) {
    if (s[k][i] == 'W') {
      if (f[k][i][1] < ans) ans = f[k][i][1];
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
