import java.util.Scanner;
public class LakeCounting {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int p=0;
int N = in.nextInt();
int M = in.nextInt();
boolean b[][] = new boolean[N][M];
for(int i = 0;i< N;i++)
{
for(int j =0;j<M;j++)
{
byte s = in.nextByte();
char c= (char)s;
if(c=='W')
b[i][j]=true;
else
b[i][j]=false;
}
}
in.close();
for(int i =1;i<N-1;i++)
{
for(int j=1;j<M-1;j++)
{
if(b[i][j]==true&&b[i-1][j]==true&&b[i+1][j]==true&&b[i][j-1]==true&&b[i][j+1]==true)
p++;
}
}
System.out.print(p);
}
}
public class LakeCounting {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int p=0;
int N = in.nextInt();
int M = in.nextInt();
boolean b[][] = new boolean[N][M];
for(int i = 0;i< N;i++)
{
for(int j =0;j<M;j++)
{
byte s = in.nextByte();
char c= (char)s;
if(c=='W')
b[i][j]=true;
else
b[i][j]=false;
}
}
in.close();
for(int i =1;i<N-1;i++)
{
for(int j=1;j<M-1;j++)
{
if(b[i][j]==true&&b[i-1][j]==true&&b[i+1][j]==true&&b[i][j-1]==true&&b[i][j+1]==true)
p++;
}
}
System.out.print(p);
}
}