using System;
using System.Numerics;

public class Zadatak5 
{
    static bool sveTacke(char[,] matrix, int N, int M)
    {
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < M; j++)
            {
                if (matrix[i, j] == '.') return false;
            }
        }
        return true;
    }


    public static void Main() 
    {
        string[] a = Console.ReadLine().Split();
        int n = int.Parse(a[0]);
        int m = int.Parse(a[1]);
        char[,] pozar = new char[n, m];
        bool[,] provera = new bool[n, m];

        for (int i = 0; i < n; i++) 
        {
            string s = Console.ReadLine();

            for (int j = 0; j < m; j++) 
            {
                pozar[i, j] = s[j];             
            }
        }

        int elitra = 1;
        while (sveTacke(pozar, n, m) == false)
        {

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    if (pozar[i, j] == 'X' && provera[i, j] == false)
                    {
                        if (i - 1 >= 0 && pozar[i - 1, j] != '*' && pozar[i - 1, j] != 'X')
                        {
                            pozar[i - 1, j] = 'X';
                            provera[i - 1, j] = true;
                        }
                        if (i + 1 <= n - 1 && pozar[i + 1, j] != '*' && pozar[i + 1, j] != 'X')
                        {
                            pozar[i + 1, j] = 'X';
                            provera[i + 1, j] = true;
                        }
                        if (j - 1 >= 0 && pozar[i, j - 1] != '*' && pozar[i, j - 1] != 'X')
                        {
                            pozar[i, j - 1] = 'X';
                            provera[i, j - 1] = true;
                        }
                        if (j + 1 <= m - 1 && pozar[i, j + 1] != '*' && pozar[i, j + 1] != 'X')
                        {
                            pozar[i, j + 1] = 'X';
                            provera[i, j + 1] = true;
                        }
                    }
                }
            }

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    provera[i, j] = false;
                }
            }

            for (int i = 0; i < n; i++)
            {

                for (int j = 0; j < m; j++)
                {

                    if (pozar[i, j] == 'S' && provera[i, j] == false)
                    {
                        if (i - 1 >= 0 && pozar[i - 1, j] == '.')
                        {
                            pozar[i - 1, j] = 'S';
                            provera[i - 1, j] = true;
                            elitra++;
                        }
                        if (i + 1 <= n - 1 && pozar[i + 1, j] == '.')
                        {
                            pozar[i + 1, j] = 'S';
                            provera[i + 1, j] = true;
                            elitra++;
                        }
                        if (j - 1 >= 0 && pozar[i, j - 1] == '.')
                        {
                            pozar[i, j - 1] = 'S';
                            provera[i, j - 1] = true;
                            elitra++;
                        }
                        if (j + 1 <= m - 1 && pozar[i, j + 1] == '.')
                        {
                            pozar[i, j + 1] = 'S';
                            provera[i, j + 1] = true;
                            elitra++;
                        }
                    }
                }
            }

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    provera[i, j] = false;
                }
            }
        }


        Console.WriteLine(elitra);

    }
}