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

namespace Pozar
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string[] pods = new string[2];
            int N, M;
            pods=Console.ReadLine().Split(' '); 
            N=Convert.ToInt32(pods[0]);
            M = Convert.ToInt32(pods[1]);
            string[,]matrica=new string[N, M];
            string red;
            int polja = 0;
            for(int i = 0; i < N; i++)
            {
                red = Console.ReadLine();
                for(int j = 0;j < M; j++) 
                {
                    matrica[i, j] = red[j].ToString().ToUpper();
                }
            }
            for(int i = 0;i < N; i++) 
            {
                for(int j = 0; j < M; j++) 
                {
                    if (matrica[i, j] == "X" && matrica[i,j]==".")
                    {
                        if (i - 1 >= 0) matrica[i - 1, j] = "X";
                        if (i + 1 < N) matrica[i + 1, j] = "X";
                        if (j - 1 >= 0) matrica[i, j - 1] = "X";
                        if (j + 1 < M) matrica[i, j + 1] = "X";
                        polja--;
                    }
                     if (matrica[i, j] == "*")
                     { polja--; 
                     }
                     if (matrica[i, j] == ".")
                     {
                        if (matrica[i, j] == "." && matrica[i, j] == "X") 
                        {
                            polja--;
                        }
                        if (matrica[i, j] == "." && matrica[i, j] == "S")
                        {
                            polja++;
                        }
                    }
                     if (matrica[i, j] == "S" && matrica[i,j]==".") 
                     {
                        matrica[i,j]= "S";  
                        polja++; 
                     }
                }
            }
            Console.WriteLine(polja);
            Console.ReadKey();
        }
    }
}