#include <bits/stdc++.h>   using namespace std;   int main() {     string str[1009];     int n, m;     while (cin >> n >> m) {       for (int i = 0; i < n; i++) cin >> str[i];       int ret = 0, cury = 0;       for (int i = 0; i < n; i++) {         int right = cury;         if (i % 2 == 0) {           for (int j = 0; j < m; j++)             if (str[i][j] ==  W ) right = j;           int right1 = cury;           if (i < n - 1)             for (int j = 0; j < m; j++)               if (str[i + 1][j] ==  W ) right1 = j;           right = max(right, right1);           ret += (right - cury);           cury = right;         } else {           int left = cury, left1 = cury;           for (int j = m - 1; j >= 0; j--)             if (str[i][j] ==  W ) left = j;           if (i < n - 1)             for (int j = m - 1; j >= 0; j--)               if (str[i + 1][j] ==  W ) left1 = j;           left = min(left, left1);           ret += (cury - left);           cury = left;         }       }       int row = 0;       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++)           if (str[i][j] ==  W ) row = i;       ret += row;       cout << ret << endl;     }     return 0;   }   