h, w = gets.chomp.split.map(&:to_i)
s = []
h.times do |hi|
  s[hi] = gets.chomp.split('')
end

# 上：( 0, -1)
# 右：( 1,  0)
# 下：( 0,  1)
# 左：(-1,  0)

ans = 0

h.times do |hi|
  w.times do |wi|
    next if s[hi][wi] == '#'
    # (hi, wi)をスタート地点にする
    queue = [[hi, wi, 0]]
    # 各マスへの最短コストたち
    mins = {}
    # puts "hi = #{hi}, wi = #{wi}"
    while queue.size > 0
      y, x, c = queue.pop
      # puts "  y = #{y}, x = #{x}, c = #{c}"
      [[0,-1],[1,0],[0,1],[-1,0]].each do |d|
        ny = y + d[0]
        nx = x + d[1]
        next if nx < 0 || ny < 0 || nx >= w || ny >= h
        next if s[ny][nx] == '#'

        # puts "    (ny, nx) = (#{ny}, #{nx})"
        # puts "    mins[[#{ny}, #{nx}]] = #{mins[[ny, nx]]}"

        if mins[[ny, nx]].nil? || (mins[[ny, nx]] && c + 1 < mins[[ny, nx]])
          mins[[ny, nx]] = c + 1
          queue.push([ny, nx, c + 1])
        end
      end
    end

    ans = [ans, mins.values.max].max
  end
end

puts ans
