using System;

namespace StevaC
{
    internal class Program
    {
        static void Main()
        {
            string[] input = Console.ReadLine().Split();
            int N = int.Parse(input[0]), M = int.Parse(input[1]); //N - redovi, M -
            char[,] mat = new char[N, M];
            char[] maze;
            for (int i = 0; i < N; i++)
            {
                maze = Console.ReadLine().ToCharArray();
                for (int j = 0; j < M; j++)
                    mat[i, j] = maze[j];
            }

            bool over = false;
            while (!over)
            {
                for (int i = 0; i < N; i++)
                    for (int j = 0; j < M; j++)
                    {
                        if (mat[i, j] == 'A')
                            mat[i, j] = 'S';
                        if (mat[i, j] == 'F')
                            mat[i, j] = 'X';
                    }
                over = true;
                for (int i = 0; i < N; i++)
                    for (int j = 0; j < M; j++)
                        if (mat[i, j] == '.')
                        {
                            AdjacentTiles(i, j, mat);
                            if (mat[i, j] == 'A') over = false;
                        }
            }
            int count = 0;
            foreach (var item in mat)
                if (item == 'S') count++;
            Console.WriteLine(count);
        }
        static char[,] AdjacentTiles(int i, int j, char[,] mat)
        {
            bool fire = false;
            try
            {
                if (mat[i + 1, j] == 'S') mat[i, j] = 'A';
                if (mat[i + 1, j] == 'X') fire = true;
            }
            catch (Exception e) { }
            try
            {
                if (mat[i, j + 1] == 'S') mat[i, j] = 'A';
                if (mat[i, j + 1] == 'X') fire = true;
            }
            catch (Exception e) { }
            try
            {
                if (mat[i - 1, j] == 'S') mat[i, j] = 'A';
                if (mat[i - 1, j] == 'X') fire = true;
            }
            catch (Exception e) { }
            try
            {
                if (mat[i, j - 1] == 'S') mat[i, j] = 'A';
                if (mat[i, j - 1] == 'X') fire = true;
            }
            catch (Exception e) { }
            if (fire) mat[i, j] = 'F';
            return mat;
        }
    }
}