using System;
using System.Reflection.Metadata.Ecma335;
using System.Runtime.InteropServices;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            
            int m = int.Parse(s[1]);
            int q = int.Parse(s[0]);

            char[] map = new char[m];

            string str;

            int steve = -1;
            for (int t = 0; t < q; t++)
            {
                str = Console.ReadLine();
                for (int i = 0; i < m; i++)
                {
                    map[i] = str[i];
                    if (str[i] == 'S')
                        steve = i;
                }
            }
            int n=1;
            bool broken = false;

            
            int k = steve;

                while (k > 0)
                {
                    k--;
                    if (map[k] == '*')
                    {
                        n += (steve - k) - 1;
                        broken = true;
                        break;
                    }
                    if (map[k] == 'X')
                    {
                        n += (steve - k - 1) / 2;
                        broken = true;
                        break;
                    }

                }
                if (!broken)
                    n += steve;
 
            k = steve;
            broken = false;
            if (k < m - 1)
            {
                while (k < m - 1)
                {
                    k++;
                    if (map[k] == '*')
                    {
                        n += (k - steve) - 1;
                        broken = true;
                        break;
                    }
                    if (map[k] == 'X')
                    {
                        n += (k - steve - 1) / 2;
                        broken = true;
                        break;
                    }

                }
                if (!broken)
                    n += (m - steve) - 1;
            }
            Console.WriteLine(n);
        }

    }
}