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

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
                        string[] s = Console.ReadLine().Split();
            int n = int.Parse(s[0]);
            int m = int.Parse(s[1]);
            char[,] x = new char[n, m];
            for (int i = 0; i < n; i++)
            {
                char[] p = Console.ReadLine().ToCharArray();
                for (int j = 0; j < m; j++)
                {
                    x[i, j] = p[j];
                }
            }
            int[,] y = new int[n, m];
            bool z = true;
            int br = 0;
            int pom = 0;
            while (z)
            {
                int k1 = 0;
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < m; j++)
                    {
                        if (x[i, j] == '.')
                        {
                            if (i > 0)
                            {
                                if (x[i - 1, j] == 'X' && y[i - 1, j] == pom)
                                {
                                    x[i, j] = 'X';
                                    y[i, j] = pom + 1;
                                }
                            }
                            if (i < n - 1)
                            {
                                if (x[i + 1, j] == 'X' && y[i + 1, j] == pom)
                                {
                                    x[i, j] = 'X';
                                    y[i, j] = pom + 1;
                                }
                            }
                            if (j > 0)
                            {
                                if (x[i, j - 1] == 'X' && y[i, j - 1] == pom)
                                {
                                    x[i, j] = 'X';
                                    y[i, j] = pom + 1;
                                }
                            }
                            if (j < m - 1)
                            {
                                if (x[i, j + 1] == 'X' && y[i, j + 1] == pom)
                                {
                                    x[i, j] = 'X';
                                    y[i, j] = pom + 1;
                                }
                            }
                            if (x[i, j] == '.')
                            {
                                if (i > 0)
                                {
                                    if (x[i - 1, j] == 'S' && y[i - 1, j] == pom)
                                    {
                                        x[i, j] = 'S';
                                        y[i, j] = pom + 1;
                                    }
                                }
                                if (i < n - 1)
                                {
                                    if (x[i + 1, j] == 'S' && y[i + 1, j] == pom)
                                    {
                                        x[i, j] = 'S';
                                        y[i, j] = pom + 1;
                                    }
                                }
                                if (j > 0)
                                {
                                    if (x[i, j - 1] == 'S' && y[i, j - 1] == pom)
                                    {
                                        x[i, j] = 'S';
                                        y[i, j] = pom + 1;
                                    }
                                }
                                if (j < m - 1)
                                {
                                    if (x[i, j + 1] == 'S' && y[i, j + 1] == pom)
                                    {
                                        x[i, j] = 'S';
                                        y[i, j] = pom + 1;
                                    }
                                }
                            }
                            if (x[i, j] == '.')
                            {
                                y[i, j] = pom + 1;
                                k1++;
                            }
                            if (x[i, j] == 'S' || x[i, j] == '*' || x[i, j] == 'X' && y[i, j] == pom)
                            {
                                y[i, j] = pom + 1;
                            }
                        }
                    }
                }
                if (k1 == 0)
                    z = false;
                pom++;
            }
            int zbu = 0;
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    if (x[i, j] == 'S')
                    {
                        zbu++;
                    }
                }
            }
            Console.WriteLine(zbu);
        }
    }
}