#include <iostream>

using namespace std;

int main() {
    int height, width;
    cin >> height >> width;
    char board[height][width];
    for (int i = 0; i < height; i++) {
        string row;
        cin >> row;
        for (int j = 0; j < width; j++) board[i][j] = row[j];
    }
    char newBoard[height][width];
    copy(&board[0][0], &board[0][0] + height * width, &newBoard[0][0]);
    int tiles = 1;
    bool increased = true;
    while (increased) {
        increased = false;
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < width; j++) {
                if (board[i][j] != '.') continue;
                else if (board[i][min(j+1, width-1)] == 'X' ||
                    board[min(i+1, height-1)][j] == 'X' ||
                    board[i][max(j-1, 0)] == 'X' ||
                    board[max(i-1, 0)][j] == 'X') {
                    newBoard[i][j] = 'X';
                } else if (board[i][min(j+1, width-1)] == 'S' ||
                    board[min(i+1, height-1)][j] == 'S' ||
                    board[i][max(j-1, 0)] == 'S' ||
                    board[max(i-1, 0)][j] == 'S') {
                    newBoard[i][j] = 'S';
                    tiles += 1;
                    increased = true;
                }
            }
        }
        copy(&newBoard[0][0], &newBoard[0][0] + height * width, &board[0][0]);
    }
    cout << tiles;
    return 0;
}