#include #define rep(i,a,b) for(int i=a;i<(b);++i) #define erep(i,a,b) for(int i=a;i<=(int)(b);++i) #define per(i,a,b) for(int i=(b);i>(a);--i) #define eper(i,a,b) for(int i=((int)(a));i>=b;--i) #define pb push_back #define mp make_pair #define INF 1e18 #define MOD 1000000007 using namespace std; typedef long long ll; typedef pair P; int dy[]={0, 0, 1, -1}; int dx[]={1, -1, 0, 0}; int gcd(int a,int b){return b?gcd(b,a%b):a;} int lcm(int a,int b){return a/gcd(a, b)*b;} string s[51]; int h, w, p[52][52]; double ans = DBL_MAX; int main() { ios::sync_with_stdio ( false ); cin.tie ( 0 ); cin >> h >> w; erep(i, 1, h) cin >> s[i]; erep(i, 1, h) rep(j, 0, w) { int c = s[i][j] - '0'; p[i][j+1] = c; } erep(i, 0, h+1) { erep(j, 0, w+1) { if (i * j == 0 || i == h+1 || j == w+1) p[i][j] = -1; } } erep(i, 0, h+1) { erep(j, 0, w+1) { if (p[i][j] != -1) continue; else { double sum = 0.0; erep(k, 1, h) { erep(l, 1, w) { if (p[k][l] == 1) { sum += sqrt((i-k)*(i-k) + (j-l)*(j-l)); } } } ans = min(ans, sum); } } } printf("%.12f\n", ans); return 0; }