#include #define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++) using namespace std; typedef long long ll; int main(void) { ll H, W; cin >> H >> W; vector> P(H + 1, vector(W + 1)); REP(i, 1, H + 1) { string s; cin >> s; REP(j, 1, W + 1) { P[i][j] = s[j - 1] - '0'; } } double ans = 1e20; REP(i, 0, H + 2) REP(j, 0, W + 2) { ll cnt = 0; if(i == 0) cnt++; if(i == H + 1) cnt++; if(j == 0) cnt++; if(j == W + 1) cnt++; if(cnt != 1) continue; double t = 0; REP(y, 1, H + 1) REP(x, 1, W + 1) { if(P[y][x] == 1) { t += sqrt((i - y) * (i - y) + (j - x) * (j - x)); } } ans = min(ans, t); } printf("%.15lf\n", ans); }