#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <cmath>
using namespace std;

#define rep(i, n) for(int i = 0; i< n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
typedef long long ll;
typedef pair<double, int> P;
const ll INF = 1LL << 50;
const double EPS = 1e-12;

int dy[] = {1, 0, -1, 0};
int dx[] = {0, -1, 0, 1};
int W, H;
char field[600][600];
ll a[600][600];
ll b[600][600];

void bfs(char start, ll dist[][600]){
  queue<int> que;
  fill(&dist[0][0], &dist[0][0] + 600 * 600, INF);
  rep(i, H)rep(j, W){
    if(field[i][j] == start){
      dist[i][j] = 0;
      que.push(i * W + j);
    }
  }
  while(!que.empty()){
    int p = que.front(); que.pop();
    int x = p % W;
    int y = p / W;
    rep(i, 4){
      int y2 = y + dy[i];
      int x2 = x + dx[i];
      if((field[y2][x2] == '.' || field[y2][x2] == 's') && dist[y2][x2] == INF){
	dist[y2][x2] = dist[y][x] + 1;
	que.push(y2 * W + x2);
      }
    }
  }
}

int main(){
  while(cin >> W >> H){
    int sy = 0, sx = 0;
    rep(i, H)rep(j, W){
      cin >> field[i][j];
      if(field[i][j] == 's'){
	sy = i, sx = j;
      }
    }
    bfs('*', a);
    bfs('g', b);
    long double ub = 1e15;
    long double lb = 0;
    rep(i, 1000){
      long double mb = (ub + lb) / 2;
      long double sum = 0;
      int cnt = 0;
      rep(j, H)rep(k, W){
	if(field[j][k] == 's' || field[j][k] == '.'){
	  cnt++;
	  sum += min((long double)b[j][k], a[j][k] + mb);
	}
      }
      if(mb > sum / cnt) ub = mb;
      else lb = mb;
    }
    cout << fixed << setprecision(15) << min(lb+a[sy][sx],(long double)b[sy][sx])<< endl;
  }
  return 0;
}