def puta(a)
  for i in 0..a.size-1
    p a[i]
  end
end

def maze(i,j,c)
  #puts "i=#{i} j=#{j} c=#{c}"
  $cm[i][j]=c
  f1=$m[i+1][j] && c+1<$cm[i+1][j]
  f2=$m[i-1][j] && c+1<$cm[i-1][j]
  f3=$m[i][j+1] && c+1<$cm[i][j+1]
  f4=$m[i][j-1] && c+1<$cm[i][j-1]
  if !f1 && !f2 && !f3 && !f4
    #puts "return c=#{c}"
    return
  end

  a1,a2,a3,a4=[0,0,0,0]
  a1=maze(i+1,j,c+1) if f1
  a2=maze(i-1,j,c+1) if f2
  a3=maze(i,j+1,c+1) if f3
  a4=maze(i,j-1,c+1) if f4
#  return [a1,a2,a3,a4].max
end


def reset(h,w)
  $cm=[]
  for i in 0..h
    $cm[i]=Array.new(w+1,99)
  end
end

h,w=gets.chomp.split(" ").map{|s| s.to_i+1}
$m=[]
$m[0]=Array.new(w,false)
$m[h]=Array.new(w,false)
for i in 1..h-1
  $m[i]=gets.chomp.split("").map{ |c|
    if c=="."
      c=true
    else
      c=false
    end
  }.push(false).unshift(false)
end

ans=0
for i in 1..h-1
  for j in 1..w-1
    reset(h,w)
    maze(i,j,0)
    #puta $cm
    #puta $m
    for k in 1..h-1
      for l in 1..w-1
        ans=$cm[k][l] if $m[k][l] && ans<$cm[k][l]
      end
    end
  end
end
p ans