using System;
    internal class Program
    {
        static void Main(string[] args)
        {
            int N = 0;
            int M = 0;
            string[] stringArray = Console.ReadLine().Split(' ');
            N = Convert.ToInt32(stringArray[0]);
            M = Convert.ToInt32(stringArray[1]);

            string[] mat = new string[N];
            for (int i = 0;i < N;i++)
            {
                mat[i] = Console.ReadLine();
            }

            char[,] mat1 = new char[N, M];
            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < M; j++)
                {
                    string test = mat[i];
                    mat1[i,j] = test[j];
                }
            }
            int sum = 0;

            if (N == 1)
            {
                int temp1 = 0;
                int temp2 = 0;

                for (int i = 1; i < M; i++)
                {
                    if (mat1[N - 1, i] == 'X') { temp1 = i; }
                    if (mat1[N - 1, i] == 'S') { temp2 = i; }
                }

                if (temp2 == temp1 + 1) { sum = M - (temp1 + 1); }
                if (temp1 == temp2 + 1) { sum = M - (temp1 + 1); }
            }
            Console.WriteLine(sum);
        }
    }