
H, W = gets.strip.split(/ /).collect(&:to_i)
grid = []
H.times{
	grid << gets.strip.each_char.collect{|c| c == "#"}
}

MAX = W

def to_index(x, y)
	y * MAX + x
end

def to_axis(num)
	y = num / MAX
	x = num % MAX
	[x, y]
end

queue = []
counts = []
grid.each_with_index{|line, y|
	line.each_with_index{|c, x|
		if c
			queue << [x, y]
			counts[to_index(x, y)] = 0
		end
	}
}

while point = queue.shift
	x, y = point
	count = counts[to_index(x, y)] + 1
	[[0, 1], [0, -1], [1, 0], [-1, 0]].each{|dx, dy|
		nx = x + dx
		ny = y + dy
		if nx < 0 || nx >= W || ny < 0 || ny >= H
			next
		end
		index = to_index(nx, ny)
		nc = counts[index]
		if nc == nil || nc > count
			counts[index] = count
			queue << [nx, ny]
		end
	}
end
max = 0
W.times{|x|
	H.times{|y|
		c = counts[to_index(x, y)]
		if c > max
			max = c
		end
	}
}

puts max
