#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define MAX_V 1000
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const long long int MOD = 1000000007;
const long long int INF = 100000000000000;

int h, w;
P st, go;
char b[500][500];
ll gist[500][500], wist[500][500];
queue<P> que;
int dh[4] = {1,0,-1,0};
int dw[4] = {0,1,0,-1};
int flo = 0;

int main(){
    cin >> w >> h;
    rep(i,h) rep(j,w) cin >> b[i][j];
    rep(i,h) rep(j,w){
        if(b[i][j] == 's'){
            st.first = i;
            st.second = j;
            b[i][j] = '.';
        }
        if(b[i][j] == '.'){
            flo++;
        }
        if(b[i][j] == 'g'){
            go.first = i;
            go.second  = j;
            b[i][j] = '.';
        }
    }
    rep(i,h) rep(j,w){
        gist[i][j] = INF;
        wist[i][j] = INF;
    }
    gist[go.first][go.second] = 0;
    que.push(go);
    while(!que.empty()){
        P p = que.front();
        que.pop();
        rep(i,4){
            int nh = p.first+dh[i];
            int nw = p.second+dw[i];
            if(0>nh||nh>=h||0>nw||nw>=w) continue;
            if(b[nh][nw] != '.') continue;
            if(gist[nh][nw] <= gist[p.first][p.second]+1) continue;
            gist[nh][nw] = gist[p.first][p.second]+1;
            que.push(P(nh,nw));
        }
    }
    rep(i,h) rep(j,w){
        if(b[i][j] == '*'){
            que.push(P(i,j));
            wist[i][j] = 0;
        }
    }
    while(!que.empty()){
        P p = que.front();
        que.pop();
        rep(i,4){
            int nh = p.first+dh[i];
            int nw = p.second+dw[i];
            if(0>nh||nh>=h||0>nw||nw>=w) continue;
            if(b[nh][nw] != '.') continue;
            if(wist[nh][nw] <= wist[p.first][p.second]+1) continue;
            wist[nh][nw] = wist[p.first][p.second]+1;
            que.push(P(nh,nw));
        }
    }
    long double s = 0.0, e = 1000000000000.0, mid;
    rep(u,1000){
        mid = (s+e)/2.0;
        long double sum = 0.0;
        rep(i,h) rep(j,w){
            if(b[i][j] == '.' && go != P(i,j)){
                sum += min((long double)gist[i][j],wist[i][j]+mid);
            }
        }
        sum /= (long double)flo;
        if(mid > sum){
            e = mid;
        } else{
            s = mid;
        }
    }
    long double ans = min((long double)gist[st.first][st.second],wist[st.first][st.second]+mid);
    printf("%.15Lf\n",ans);
}