/// ! 704/ 10^, )!3!+¿!¡/[!]
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define dl double long
#define str string
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define pi pair<int, int>
#define vp vector<pi>
#define pb push_back
#define popb pop_back
#define f first
#define s second
#define t third
#define ti triple<int, int, int>

const int MOD = 1e9 + 7;
const int N = 2e5 + 5;

ll binpow(ll a, ll b) {
    ll res = 1;
    while(b > 0){
        if(b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

void solve(){
    int n, m;
    cin >> n >> m;
    vector<char> a(m);
    int s;
    vp zid;
    for(int i = 0; i < m; i++) cin >> a[i];
    for(int i = 0; i < m; i++){
        if(a[i] == 'S'){
            s = i;
            break;
        }
    }
    int l = -1, d = m;
    for(int i = s; i < m; i++){
        if(a[i] == '*' || a[i] == 'X'){
            d = i;
            break;
        }
    }
    for(int i = s; i > -1; i--){
        if(a[i] == '*' || a[i] == 'X'){
            l = i;
            break;
        }
    }
    if((a[l] == '*' && a[d] == '*') || (a[l] == '*' && d == m) || (l == -1 && a[d] == '*') || (l == -1 && d == m)){
        cout << d - l - 1;
    }
    else if((a[l] == '*' && a[d] == 'X') || (l == -1 && a[d] == 'X')){
        cout << (d - l - 1) - ((d - s) / 2);
    }
    else if((a[l] == 'X' && a[d] == '*') || (a[l] == 'X' && d == m)){
        cout << (d - l - 1) - ((s - l) / 2);
    }
    else{
        cout << (s - l) - ((s - l) / 2) + (d - s) - ((d - s) / 2) - 1;
    }

}

int main(){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false);
    solve();
    return 0;
}