# abc151 D

hhh, www = read_line.split.map(&.to_i)
c = hhh.times.to_a.map {
  read_line.chomp.chars
}

max = 1
u = Array.new(hhh){Array.new(www, false)}
hhh.times do |sh|
  www.times do |sw|
    hhh.times do |gh|
      www.times do |gw|
        next if sh <= gh || sw == gw

        u.map! {|uu|uu.map! {|uuu| false }}

        tmpmax = 0
        len = 0
        queue = [ [sh, sw, len] ]
        until queue.empty?
          s = queue.shift
          h, w, len = s[0], s[1], s[2]
          tmpmax = len if max < len

          # [
          #   [h-1, w],
          #   [h+1, w],
          #   [h, w-1],
          #   [h, w+1]
          # ].select{|(hh,ww)|
          #   0 <= hh && hh < hhh && 0 <= ww && ww < www \
          #   && c[hh][ww] == '.' && !u[hh][ww]
          # }.each { |(hh, ww)|
          #   queue << [hh, ww, len+1]
          #   u[hh][ww] = true
          # }
          if 0 <= h-1 && c[h-1][w] == '.' && !u[h-1][w]
            queue << [h-1, w, len+1]
            u[h-1][w] = true
          end
          if h+1 < hhh && c[h+1][w] == '.' && !u[h+1][w]
            queue << [h+1, w, len+1]
            u[h+1][w] = true
          end
          if 0 <= w-1 && c[h][w-1] == '.' && !u[h][w-1]
            queue << [h, w-1, len+1]
            u[h][w-1] = true
          end
          if w+1 < www && c[h][w+1] == '.' && !u[h][w+1]
            queue << [h, w+1, len+1]
            u[h][w+1] = true
          end
        end
        max = tmpmax if tmpmax > max
      end
    end
  end
end
p max
