import math H, W = map(int, input().split()) dots = [] for y in range(1, H + 1): line = input().strip() for x in range(1, W + 1): if line[x - 1] == '1': dots.append((x, y)) if not dots: print("0.00000000") else: min_total = float('inf') positions = [] # Left edge: x=0, y from 1 to H for y in range(1, H + 1): positions.append((0, y)) # Right edge: x=W+1, y from 1 to H for y in range(1, H + 1): positions.append((W + 1, y)) # Top edge: y=0, x from 1 to W for x in range(1, W + 1): positions.append((x, 0)) # Bottom edge: y=H+1, x from 1 to W for x in range(1, W + 1): positions.append((x, H + 1)) for (sx, sy) in positions: total = 0.0 for (x, y) in dots: dx = sx - x dy = sy - y dist = math.sqrt(dx ** 2 + dy ** 2) total += dist if total < min_total: min_total = total print("{0:.8f}".format(min_total))