# 0:17-
h, w = gets.to_s.split.map{|t| t.to_i }

# p ".#".bytes #=> [46, 35]
a = Array.new(h){ gets.to_s.chomp.bytes }

inf = h + w
dist = Array.new(h){ [inf] * w }

dxy = [[1, 0], [0, 1], [-1, 0], [0, -1]]

h.times do |sx|
  w.times do |sy|
    
    next if a[sx][sy] == 46
    
    q = [[sx, sy, 0]]
    dist[sx][sy] = 0
    # p q
    while q.any?
      
      q.uniq!
      x, y, t = q.shift
      dxy.each do |(dx, dy)|
        nx = x + dx
        ny = y + dy
        nt = t + 1
        # p [nx, ny, nt]
        next if !(0 <= nx && nx < h && 0 <= ny && ny < w)
        if dist[nx][ny] > nt
          dist[nx][ny] = nt
          q.push([nx, ny, nt])
        end
      end
    end
  end
end
# p dist[0]; p dist[1]; p dist[2]
ans = 0
h.times do |x|
  t = dist[x].max
  ans = t if ans < t
end

p ans