using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void zamena(string[,] a, string[,] b, int n, int m, int i, int j, string k)
        {
            if (i > 0 && a[i - 1, j] == k)
                b[i, j] = a[i - 1, j];
            if (i < n - 1 && a[i, j] != "X" && a[i + 1, j] == k)
                b[i, j] = a[i + 1, j];
            if (j > 0 && a[i, j] != "X" && a[i, j - 1] == k)
                b[i, j] = a[i, j - 1];
            if (j < m - 1 && a[i, j] != "X" && a[i, j + 1] == k)
                b[i, j] = a[i, j + 1];
        }
        static void lav(string[,] a, int n, int m, int brx)
        {
            bool p = false;
            string[,] b = new string[n, m];
            int br = 0;
            for(int i = 0; i < n; i++)
            {
                for(int j = 0; j < m; j++)
                {
                    b[i, j] = a[i, j];
                    if (a[i, j] == ".")
                    {
                        zamena(a, b, n, m, i, j, "S");
                        if(brx>0)
                            zamena(a, b, n, m, i, j, "X");
                    }
                    if (b[i, j] == "S")
                        br++;
                    if (b[i, j] != a[i, j])
                        p = true;
                }
            }
            for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++)
                    a[i, j] = b[i, j];
            if (p)
                lav(a, n, m, brx);
            else
                Console.WriteLine(br);
        }
        static void Main(string[] args)
        {
            string[] c = Console.ReadLine().Split(' ');
            int n=int.Parse(c[0]), m = int.Parse(c[1]),brx=0,brz=0;
            string[,] a = new string[n, m];
            for(int i = 0; i < n; i++)
            {
                c = Console.ReadLine().Split(' ');
                for(int j = 0; j<m; j++)
                {
                    if (c[j] == "X")
                        brx++;
                    else if (c[j] == "*")
                        brz++;
                    a[i, j] = c[j];
                }
            }
            if (brx == 0 && brz==0)
                Console.WriteLine(n*m);
            else
                lav(a,n,m,brx);
        }
    }
}