#include <bits/stdc++.h>
using namespace std;
int n, m;
char s[160][160];
int main() {
  scanf("%d %d ", &n, &m);
  for (int i = 0; i < n; i++) gets(s[i]);
  vector<int> row;
  vector<pair<int, int> > y;
  for (int i = 0; i < n; i++) {
    int low = m, high = -1;
    for (int j = 0; j < m; j++)
      if (s[i][j] == 'W') {
        low = j;
        break;
      }
    for (int j = m - 1; j >= 0; j--)
      if (s[i][j] == 'W') {
        high = j;
        break;
      }
    if (low <= high) {
      row.push_back(i);
      y.push_back(pair<int, int>(low, high));
    }
  }
  int result = 0, col = 0, last_row = 0;
  for (int i = 0; i < row.size(); i++) {
    int y_min = y[i].first, y_max = y[i].second;
    if (row[i] % 2) {
      result += abs(col - y_max);
      col = y_min;
    } else {
      result += abs(col - y_min);
      col = y_max;
    }
    result += y_max - y_min;
    result += row[i] - last_row;
    last_row = row[i];
  }
  printf("%d\n", result);
  return 0;
}
