#include <bits/stdc++.h>
const double eps = (1e-10);
const double PI = acos(-1.0);
using namespace std;
int dcmp(double a, double b) {
  return fabs(a - b) <= eps ? 0 : (a > b) ? 1 : -1;
}
int getBit(int num, int idx) { return ((num >> idx) & 1) == 1; }
int setBit1(int num, int idx) { return num | (1 << idx); }
int setBit0(int num, int idx) { return num & ~(1 << idx); }
int flipBit(int num, int idx) { return num ^ (1 << idx); }
int countNumBit1(int mask) {
  int ret = 0;
  while (mask) {
    mask &= (mask - 1);
    ++ret;
  }
  return ret;
}
vector<string> v;
int arr[150 + 9][2], vis[150 + 9];
int main() {
  int n, m;
  cin >> n >> m;
  string st;
  int cnt = 0;
  for (int i = 0; i < n; i++) arr[i][0] = 300000, arr[i][1] = -1;
  for (int i = 0; i < n; i++) {
    cin >> st;
    int fl = 1;
    for (int j = 0; j < m; j++) {
      if (st[j] == 'W' && fl) arr[i][0] = j, fl = 0;
      if (st[j] == 'W') vis[i]++, cnt++, arr[i][1] = j;
    }
    v.push_back(st);
  }
  int l = 1;
  int str = 0;
  int cost = 0, ct = 0, id;
  arr[n][0] = 300000;
  arr[n][1] = -1;
  for (int i = 0; i < n; i++) {
    if (l)
      id = max(str, max(arr[i][l], arr[i + 1][l]));
    else
      id = min(str, min(arr[i][l], arr[i + 1][l]));
    cost += abs(id - str);
    ct += vis[i];
    if (ct == cnt) {
      cout << cost << endl;
      return 0;
    }
    if (i + 1 < n) cost++;
    str = id;
    l ^= 1;
  }
}
