#include using namespace std; double find_min_d(const vector & P, const int H, const int W, int X, int Y, double tmp = 1e9){ double d = 0; for (int y = 0; y < H; ++y){ for (int x = 0; x < W; ++x){ if (P[y][x] == '1'){ d += sqrt((x - X)*(x - X) + (y - Y) * (y - Y)); } } if (d > tmp) break; } return min(tmp, d); } int main() { int H, W; cin >> H >> W; vector P(H); for (auto & p : P) cin >> p; double ans = 1e9; for (int Y = 0; Y < H; ++Y) ans = find_min_d(P, H, W, -1, Y, ans); for (int Y = 0; Y < H; ++Y) ans = find_min_d(P, H, W, W, Y, ans); for (int X = 0; X < W; ++X) ans = find_min_d(P, H, W, X, -1, ans); for (int X = 0; X < W; ++X) ans = find_min_d(P, H, W, X, H, ans); cout << fixed << setprecision(15) << ans << endl; return 0; }