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

namespace zadatak_3_steva_v2
{
    internal class Program
    {
        static void Main(string[] args)
        {
            
            string[] input = Console.ReadLine().Split(' ');
            long N = long.Parse(input[0]);
            long M = long.Parse(input[1]);
            char[,] matrix = new char[N, M];

            long[,] matrixS = new long[N, M];
            long[,] matrixX = new long[N, M];
            for (int i = 0; i < N; i++)
            {
                string input1 = Console.ReadLine();
                char[] temp = input1.ToCharArray();
                for (int j = 0; j < M; j++) 
                {
                    matrix[i, j] = temp[j];
                }
            }
            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < M; j++)
                {
                    if (matrix[i,j] == '*')
                    {
                        matrixS[i, j] = -2;          //-1 je zid
                        matrixX[i,j] = -2;
                    }
                    else if (matrix[i,j] == 'X')
                    {
                        matrixX[i,j] = 1;                
                        matrixS[i, j] = 0;
                    }
                    else if(matrix[i,j] == 'S')
                    {
                        matrixS[i, j] = 1;
                        matrixX[i, j] = 0;            //1 su Steva i vatre
                    }
                    else
                    {
                        matrixS[i, j] = 0;                   //0 je prazno polje
                        matrixX[i, j] = 0;
                    }
                }
            }


            for(int i = 0; i < N; i++)
            {
                for(int j = 0; j < M; j++)
                {
                    if(matrix[i,j] == 'S')
                    {
                        AdjecentPlacement(ref matrixS, i, j, 2);
                    }
                    else if(matrix[i,j] == 'X')
                    {
                        AdjecentPlacement(ref matrixX, i, j, 2);   
                    }
                }
            }
            long sum = 0;
            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < M; j++)
                {
                    if (matrixS[i, j] > matrixX[i, j])
                        sum++;
                }            
            }
            Console.WriteLine(sum);

        }
        static void AdjecentPlacement(ref long[,] matrix, long x, long y,long turn)
        {
            long N = matrix.GetLength(0);
            long M = matrix.GetLength(1);
            for (int i = -1; i <= 1; i++) 
            {
                if (x + i>= 0 && x + i< N && y >= 0 && y< M && (matrix[x +i, y] == 0 || matrix[x+i,y]>turn))
                {
                    matrix[x + i, y] = turn; 
                    AdjecentPlacement(ref matrix, x + i, y, turn + 1); 
                }
                if (x >= 0 && x < N && y + i >= 0 && y + i < M && matrix[x,y+ i] == 0&&(matrix[x, y+i] == 0 || matrix[x, y+i] > turn))
                {
                    matrix[x, y + i] = turn;
                    AdjecentPlacement(ref matrix, x, y + i, turn + 1); 
                }
            }

        }
    }
}