#include #include #include #include #include #include #include using namespace std; using ll = long long; int h, w; char p[50][51]; double f(int x, int y) { double s = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (p[i][j] == '1') { int a = i - x; int b = j - y; s += sqrt(a * a + b * b); } } } return s; } int main() { cin >> h >> w; for (int i = 0; i < h; i++) { cin >> p[i]; } double r = 1e100; for (int i = 0; i < h; i++) { r = min(r, f(-1, i)); r = min(r, f(h, i)); r = min(r, f(i, -1)); r = min(r, f(i, w)); } printf("%.8f\n", r); return 0; }