#include <bits/stdc++.h>
using namespace std;
char a[1000][1000];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);
    int n, m;
    cin >> n >> m;
    int x = 0, y = 0;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
            if (a[i][j] == 'S') {
                x = i;
                y = j;
            }
        }
    if (n == 1) {
        int levo = 0;
        int desno = 0;
        int j;
        for (j = y - 1; j >= 0 && a[0][j] == '.'; j--);
        levo = y - j - 1;
        if (j >= 0 && a[0][j] == 'X')
            levo /= 2;
        for (j = y + 1; j < m && a[0][j] == '.'; j++);
        desno = j - y - 1;
        if (j < m && a[0][j] == 'X')
            desno /= 2;
        cout << levo + desno + 1 << '\n';
        return 0;
    }
    return 0;
}