$h, $w = gets.split.map(&:to_i)
$s = []
$h.times do
  $s << gets.chomp
end
$d = [[0, 1], [0, -1], [1, 0], [-1, 0]]
def bfs(sx, sy)
  bfs_map = Array.new($h) { Array.new($w, Float::INFINITY) }
  bfs_map[sy][sx] = 0
  q = []
  q << [sy, sx, 0]
  
  until q.empty?
    y, x, dist = q.shift
    $d.each do |dy, dx|
      ny = y + dy
      nx = x + dx
      next unless nx >= 0 && nx < $w && ny >= 0 && ny < $h && $s[ny][nx] != "#"
      if bfs_map[ny][nx] > dist + 1
        bfs_map[ny][nx] = dist + 1
        q << [ny, nx, dist + 1]
      end
    end
  end
  res = 0
  bfs_map.each do |row|
    # t = row.dele
    # p row, t if sy == 2 && sx == 0
    # res = t if t != Float::INFINITY && t > res
    row.each do |c|
      if c != Float::INFINITY && c > res
        res = c
      end
    end
  end#[gy][gx]
  return res
end

ans = -1
$h.times do |sy|
  $w.times do |sx|
    t = bfs(sx, sy)
    ans = t if t > ans
  end
  # ssy = s[sy]
  # $w.times do |sx|
  #   next if ssy[sx] == "#"
  #   $h.times do |gy|
  #     sgy = s[gy]
  #     $w.times do |gx|
  #       if sgy[gx] == "."
  #         tmp = bfs(s, sx, sy, gx, gy)
  #         ans = tmp if tmp > ans
  #       end
  #     end
  #   end
  # end
end
p ans
