#include using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) #define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++) #define ALL(x) (x).begin(), (x).end() const double PI = acos(-1); double calc(int y, int x, const vector &bd) { double ret = 0; REP (i, bd.size()) REP (j, bd[i].size()) { if (bd[i][j] == '1') ret += hypot(y - i, x - j); } return ret; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int h, w; cin >> h >> w; vector bd(h); REP (i, h) cin >> bd[i]; double ret = 1e100; REP (i, w) { ret = min(ret, calc(-1, i, bd)); ret = min(ret, calc(h, i, bd)); } REP (i, h) { ret = min(ret, calc(i, -1, bd)); ret = min(ret, calc(i, w, bd)); } cout << fixed << setprecision(12) << ret << endl; return 0; }