#include <iostream>
#include <vector>
#include <climits>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;

    vector<char> lavirint(m);
    vector<int> vatra(m, INT_MAX);
    vector<int> stevo(m, INT_MAX);

    int pStevoa = -1;
    int pVatre = -1;

    for (int j = 0; j < m; j++) {
        cin >> lavirint[j];

        if (lavirint[j] == 'S') {
            pStevoa = j;
            stevo[j] = 0;
        }

        if (lavirint[j] == 'X') {
            pVatre = j;
            vatra[j] = 0;
        }
    }

    for (int j = pVatre - 1; j >= 0; j--){
        if (lavirint[j] != '*')
            vatra[j] = vatra[j + 1] + 1;
    }

    for (int j = pVatre + 1; j < m; j++){
        if (lavirint[j] != '*')
            vatra[j] = vatra[j - 1] + 1;
    }

    for (int j = pStevoa - 1; j >= 0; j--){
        if (lavirint[j] != '*')
            stevo[j] = stevo[j + 1] + 1;
    }

    for (int j = pStevoa + 1; j < m ; j++){
        if (lavirint[j] != '*')
            stevo[j] = stevo[j - 1] + 1;
    }

    int br = 0;
    for (int j = 0; j < m; j++) {
        if (lavirint[j] == '.' || lavirint[j] == 'S') {
            if (stevo[j] != INT_MAX && vatra[j] > stevo[j])
                br++;
        }
    }

    cout << br;

    return 0;
}