#include using namespace std; const double INF = 10000000; int main(){ int H, W; cin >> H >> W; vector> P(H, vector(W)); for (int i = 0; i < H; i++){ for (int j = 0; j < W; j++){ cin >> P[i][j]; } } double ans = INF; for (int i = -1; i <= H; i++){ for (int j = -1; j <= W; j++){ if (0 <= i && i < H && 0 <= j && j < W){ double sum = 0; for (int y = 0; y < H; y++){ for (int x = 0; x < W; x++){ if (P[y][x] == 1){ sum += sqrt(pow(y - i, 2) + pow(x - j, 2)); } } } ans = min(ans, sum); } } } cout << ans << endl; }