#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); int H,W; cin >> H >> W; vector P(H); rep(i,H) cin >> P[i]; using ld = long double; ld ans = 1e18; for(int x = 0; x <= H + 1; x++) { for(int y = 0; y <= W + 1; y++) { int cnt = (x == 0) + (x == H + 1) + (y == 0) + (y == W + 1); if(cnt == 1) { ld cost = 0; rep(i,H)rep(j,W)if(P[i][j] == '1') { cost += sqrtl((x - (i+1)) * (x - (i+1)) + (y - (j+1)) * (y - (j+1))); } ans = min(ans, cost); } } } cout << fixed << setprecision(20) << ans << endl; }