#include #define rep(i,a,b) for(int i=int(a);i V,int h,int w){ double ans = 0; rep(i,0,H){ rep(j,0,W){ if(V[i][j] == '0')continue; double h2 = i + 1,w2 = j + 1; ans += sqrt( (h - h2) * (h - h2) + (w - w2) * (w - w2) ); } } return ans; } main(){ cin >> H >> W; vector V(H); rep(i,0,H)cin >> V[i]; double mini = INF; rep(i,1,H+1){ mini = min(mini, calc(V, i, W+1)); mini = min(mini, calc(V, i, 0)); } rep(i,1,W+1){ mini = min(mini, calc(V, 0, i)); mini = min(mini, calc(V, H+1, i)); } printf("%.9lf\n",mini); }