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

namespace Steva___Lavirint___Takmicenje
{
    class Program
    {

        struct maze
        { 
            public string polje;
            public bool red;
        }

        static void provera1(int N, int M, int i, int j, maze[,] m)
        {

            if (i - 1 >= 0 && m[i - 1, j].polje == "." && m[i - 1, j].red){ m[i - 1, j].polje = "X"; m[i - 1, j].red = false; }
            if (i + 1 <= N - 1 && m[i + 1, j].polje == "." && m[i + 1, j].red) { m[i + 1, j].polje = "X"; m[i + 1, j].red = false; }
            if (j - 1 >= 0 && m[i, j - 1].polje == "." && m[i, j - 1].red) { m[i, j - 1].polje = "X"; m[i, j - 1].red = false; }
            if (j + 1 <= M - 1 && m[i, j + 1].polje == "." && m[i, j + 1].red) { m[i, j + 1].polje = "X"; m[i, j + 1].red = false; }
            
        }
        static void provera2(int N, int M, int i, int j, maze[,] m)
        {

            if (i - 1 >= 0 && m[i - 1, j].polje == "." && m[i - 1, j].red) { m[i - 1, j].polje = "S"; m[i - 1, j].red = false; }
            if (i + 1 <= N - 1 && m[i + 1, j].polje == "." && m[i + 1, j].red) { m[i + 1, j].polje = "S"; m[i + 1, j].red = false; }
            if (j - 1 >= 0 && m[i, j - 1].polje == "." && m[i, j - 1].red) { m[i, j - 1].polje = "S"; m[i, j - 1].red = false; }
            if (j + 1 <= M - 1 && m[i, j + 1].polje == "." && m[i, j + 1].red) { m[i, j + 1].polje = "S"; m[i, j + 1].red = false; }

        }

        static maze[,] transfor(int N, int M, maze[,] m)
        {
            maze[,] m1 = new maze[N, M];
            while (m1 != m)
            {
                m1 = m;
                for (int r = 0; r < 5; r++)
                {
                    for (int i = 0; i < N; i++)
                    {
                        for (int j = 0; j < M; j++)
                        {
                            if (m[i, j].polje == "X" && m[i, j].red)
                            {
                                provera1(N, M, i, j, m);
                            }
                        }
                    }
                    for (int i = 0; i < N; i++)
                    {
                        for (int j = 0; j < M; j++)
                        {
                            if (m[i, j].polje == "S" && m[i, j].red)
                            {
                                provera2(N, M, i, j, m);
                            }
                        }
                    }
                    for (int i1 = 0; i1 < N; i1++)
                    {
                        for (int i2 = 0; i2 < M; i2++)
                        {
                            m[i1, i2].red = true;
                        }
                    }
                }
            }
            return m;
        }
        static void Main(string[] args)
        {
            string[] u = Console.ReadLine().Split();
            int N = int.Parse(u[0]);
            int M = int.Parse(u[1]);
            maze[,] m = new maze[N, M];
            for (int i = 0; i < N; i++)
            {
                string[] s = Console.ReadLine().Select(x => x.ToString()).ToArray();
                for (int j = 0; j < M; j++)
                {
                    m[i, j].polje = s[j];
                    m[i, j].red = true;
                }
            }
            m = transfor(N, M, m);
            int br = 0;
            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < M; j++)
                {
                    if (m[i, j].polje == "S") br++;
                }
            }
            Console.WriteLine(br);
        }
    }
}