https://www.acmicpc.net/problem/3109
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static String[][] map;
static int R, C, total;
static int[] dx = { -1,0, 1 };
static boolean check;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
st = new StringTokenizer(br.readLine());
R = Integer.parseInt(st.nextToken());
C = Integer.parseInt(st.nextToken());
map = new String[R][C];
for (int i = 0; i < R; i++) {
map[i] = br.readLine().split("");
}
total=0;
for (int i = 0; i < R; i++) {
check=false;
if(find(i, 0))
total++;
}
System.out.println(total);
}
private static boolean find(int x, int y) {
if (y == C - 1) {
check=true;
return true;
}
for (int i = 0; i < 3; i++) {
int nx = x + dx[i];
int ny = y + 1;
if (0 <= nx && nx < R && 0 <= ny && ny < C ) {
if(map[nx][ny].equals(".")) {
map[nx][ny] = "x";
find(nx, ny);
if(check)
return true;
}
}
}
return false;
}
}