#import int h,w,i,k=4e6;char s[1<<20];main(){scanf("%d%d %[^a]",&h,&w,s);for(i=h*=++w;i--;)if(s[i]>81){for(;--k>0;)k-=k+i&-s[i=(i+2+(i%w