import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.
lang.
Math.
*; import static java.
util.
Arrays.
*;
public class B{
Scanner sc
=new Scanner
(System.
in);
int INF=1<<28;
double EPS=1e-9;
int n, m;
void run(){
n=sc.nextInt();
m=sc.nextInt();
for(int j=0; j<n; j++){
map[j]=sc.next();
}
int x=0;
int step=0;
int last=0;
for(int j=0; j<n; j++){
int right;
for(right=m-1; right>=0; right--){
if(map[j].charAt(right)=='W'){
break;
}
}
int left;
for(left=0; left<m; left++){
if(map[j].charAt(left)=='W'){
break;
}
}
if(j%2==0){
if(left<m&&right>=0){
step+=abs(x-left)+abs(left-right);
x=right;
last=j;
}
}else{
if(left<m&&right>=0){
step+=abs(x-right)+abs(right-left);
x=left;
last=j;
}
}
}
step+=last;
println(step+"");
}
}
}
}
public static void main
(String[] args
){ new B().run();
}
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLm1hdGguKjsKaW1wb3J0IGphdmEuaW8uKjsKCmltcG9ydCBzdGF0aWMgamF2YS5sYW5nLk1hdGguKjsKaW1wb3J0IHN0YXRpYyBqYXZhLnV0aWwuQXJyYXlzLio7CgpwdWJsaWMgY2xhc3MgQnsKCVNjYW5uZXIgc2M9bmV3IFNjYW5uZXIoU3lzdGVtLmluKTsKCglpbnQgSU5GPTE8PDI4OwoJZG91YmxlIEVQUz0xZS05OwoKCWludCBuLCBtOwoJU3RyaW5nW10gbWFwOwoKCXZvaWQgcnVuKCl7CgkJbj1zYy5uZXh0SW50KCk7CgkJbT1zYy5uZXh0SW50KCk7CgkJbWFwPW5ldyBTdHJpbmdbbl07CgkJZm9yKGludCBqPTA7IGo8bjsgaisrKXsKCQkJbWFwW2pdPXNjLm5leHQoKTsKCQl9CgkJaW50IHg9MDsKCQlpbnQgc3RlcD0wOwoJCWludCBsYXN0PTA7CgkJZm9yKGludCBqPTA7IGo8bjsgaisrKXsKCgkJCWludCByaWdodDsK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