# abc151 D

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

max = 0
hhh.times.to_a.product(www.times.to_a).each do |(sh, sw)|
  hhh.times.to_a.product(www.times.to_a).each do |(gh, gw)|
    u = Array.new(hhh){Array.new(www, 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

p max
