using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Channels;
using System.Threading.Tasks;


namespace ConsoleApp65
{
    internal class Program
    {
        static void ispis(string[,] l, int a, int b) 
        {

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

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


                    Console.Write(l[i, j]);
                }
                Console.WriteLine();

            }

        }





        static string[,] S(string[,] l, int a, int b)
        {
            string[,] Lista = l;


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

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


                    if (l[i, j] == "S")
                    {
                        l[i, j] = "o";
                    }
                }


            }




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

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

                    if (l[i, j] == "o")
                    {

                        if (i != 0 && l[i - 1, j] != "*" && l[i - 1, j] != "o" && l[i - 1, j] != "X" && l[i - 1, j] != "p")
                        {

                            Lista[i - 1, j] = "S";
                        }

                        if (j != 0 && l[i, j - 1] != "*" && l[i, j - 1] != "o" && l[i, j - 1] != "X" && l[i, j - 1] != "p")
                        {

                            Lista[i, j - 1] = "S";
                        }



                        if (i < a - 1 && l[i + 1, j] != "*" && l[i + 1, j] != "o" && l[i + 1, j] != "X" && l[i + 1, j] != "p")
                        {

                            Lista[i + 1, j] = "S";
                        }

                        if (j < b - 1 && l[i, j + 1] != "*" && l[i, j + 1] != "o" && l[i, j + 1] != "X" && l[i, j + 1] != "p")
                        {

                            Lista[i, j + 1] = "S";
                        }


                    }

                }


            }
            for (int i = 0; i < a; i++)
            {

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


                    if (Lista[i, j] == "S")
                    {
                        Lista[i, j] = "o";
                    }
                }


            }

            return Lista;




        }




        static string[,] X (string[,] l, int a, int b) 
        {
            string[,] Lista = l;


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

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


                    if (l[i, j] == "X") 
                    {
                        l[i, j] = "p";
                    }
                }
                

            }




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

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

                    if (l[i, j] == "p")
                    {

                        if (i != 0 && l[i - 1, j] != "*"  && l[i - 1, j] != "p" && l[i - 1, j] != "S" && l[i - 1, j] != "o")
                        {

                            Lista[i - 1, j] = "X";
                        }

                        if (j != 0 && l[i, j - 1] != "*" && l[i, j - 1] != "p" && l[i, j - 1] != "S" && l[i, j - 1] != "o")
                        {

                            Lista[i, j - 1] = "X";
                        }



                        if (i < a - 1 && l[i + 1, j] != "*" && l[i + 1, j] != "p" && l[i + 1, j] != "S" && l[i + 1, j] != "o")
                        {

                            Lista[i + 1, j] = "X";
                        }

                        if (j < b - 1 && l[i, j + 1] != "*" && l[i, j + 1] != "p" && l[i, j + 1] != "S" && l[i, j + 1] != "o")
                        {

                            Lista[i, j + 1] = "X";
                        }


                    }

                }

                for (int e = 0; e < a; e++)
                {

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


                        if (Lista[e, j] == "X")
                        {
                            Lista[e, j] = "p";
                        }
                    }


                }
            }
            return Lista;




        }

        static void Main(string[] args)
        {
            string U = Console.ReadLine();

            int a = int.Parse(U.Split()[0]);
            int b = int.Parse(U.Split()[1]);

            string[,] l = new string[a, b];


            for (int i = 0; i < a; i++)
            {
                string p = Console.ReadLine();
                for (int j = 0; j < b; j++)
                {


                    l[i, j] = p.ToCharArray()[j].ToString();
                }


            }

           
            int y = 0;
            while (true) 
            {
                for (int i = 0; i < a; i++)
                {

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


                        if (l[i, j] == ".") 
                        {
                            y++;
                        }
                    }
                    

                }


               
                
                if (y == 0) 
                {
                    break;
                }

                l = X(l, a, b);
                l = S(l, a, b);
                y = 0;
            }


            int Y = 0;
            for (int i = 0; i < a; i++)
            {

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


                    if (l[i, j] == "o")
                    {
                        Y++;
                    }
                }


            }
            Console.WriteLine(Y);













        }
    }
}