#include using namespace std; using int64 = long long; int main() { int H, W; string P[55]; cin >> H >> W; for(int i = 0; i < H; i++) { string s; cin >> s; string ret = "o"; ret += s; ret += "o"; P[i + 1] = ret; } P[0] = P[H + 1] = "x"; for(int i = 0; i < W; i++) { P[0] += "o"; P[H + 1] += "o"; } P[0] += "x"; P[H + 1] += "x"; double ret = 1e9; for(int i = 0; i < H + 2; i++) { for(int j = 0; j < W + 2; j++) { if(P[i][j] == 'o') { double cost = 0; for(int k = 0; k < H + 2; k++) { for(int l = 0; l < W + 2; l++) { if(P[k][l] == '1') { cost += sqrt((i - k) * (i - k) + (j - l) * (j - l)); } } } ret = min(ret, cost); } } } cout << fixed << setprecision(10) << ret << endl; }