<?php
fscanf(STDIN, "%d%d", $H, $W);
for($i = 0; $i < $H; $i++){
  $str = fgets(STDIN);
  for($j = 0; $j < $W; $j++){
    $MAP[$i][$j] = $str[$j];
  }
}
$max = 0;
for($Y = 0; $Y < $H; $Y++){
  for($X = 0; $X < $W; $X++){
    if($MAP[$Y][$X] == "#")continue;
    $dist = 0;
    $map = $MAP;
    $c[] = [$Y,$X];
    while($c){
      $cc = [];
      foreach($c as list($y, $x)){
        foreach([[0,1],[1,0],[0,-1],[-1,0]] as list($dy, $dx)){
          if(isset($map[$y+$dy][$x+$dx]) && $map[$y+$dy][$x+$dx] == '.'){
            $map[$y+$dy][$x+$dx] = '#';
            $cc[] = [$y+$dy,$x+$dx];
          }
        }
      }
      if($cc)$dist++;
      $c = $cc;
    }
    $max = max($dist, $max);
  }
}
echo $max;

