import sequtils,strutils,math var A = newSeq[string](0) H,W : int px,py : int ans : float64 (H, W) = stdin.readline.split.map(parseInt) A.add("0") for line in stdin.lines: A.add("0" & line & "0") proc cul(a, b : int) : float64 = var r : int R : float64 for x in 1..W: for y in 1..H: if A[y][x] == '1': r = (x - a) * (x - a) + (y - b) * (y - b) R += sqrt(r.float64) return R ans = INF for i in 1..H: ans = min(ans, cul(0, i)) ans = min(ans, cul(W + 1, i)) for i in 1..W: ans = min(ans, cul(i, 0)) ans = min(ans, cul(i, H + 1)) echo ans