import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        String first = null;
        List<String> list = new ArrayList<>();
        if (in.hasNextLine()) {
            first = in.nextLine();
        } else {
            System.out.print(0);
        }
        while (in.hasNextLine()) {
            list.add(in.nextLine());
        }
        int index = -1;
        int row = -1;
        char p = 'x';
        for (int i = 0; i < list.size(); i++) {
            String str = list.get(i);
            for(int j = 0; j < str.length(); j++) {
                char sj = str.charAt(j);
                if (sj == 'W' || sj == 'S' || sj == 'A' || sj == 'D') {
                    index = j;
                    row = i;
                    p = sj;
                }
            }
        }
        List<Character> charList = new ArrayList<>();
        switch(p) {
            case 'W': {
                for(int n = row - 1; n > -1; n--) {
                    charList.add(list.get(n).charAt(index));
                }
                break;
            }
            case 'S': {
                for(int n = row + 1; n < list.size(); n++) {
                    charList.add(list.get(n).charAt(index));
                }
                break;
            }
            case 'A': {
                list.get(row).substring(0,index).chars().forEach(cs-> charList.add((char) cs));
                break;
            }
            case 'D': {
                list.get(row).substring(index + 1).chars().forEach(cs-> charList.add((char) cs));
                break;
            }
        }
        int r = 0;
        for(char c:charList) {
            if (c == '*') r++;
        }
        System.out.print(r);
    }
}