my @M;
my @res;
my ($H, $W) = map {$_ + 0} split(/\s+/o, <>);
foreach my $h (0..$H-1) {
  my $w = 0;
  foreach my $v (split(//o, <>)) {
    if ( $v eq '#' ) {
      $M[$h][$w] = 0;
    } elsif ( $v eq '.' ) {
      $M[$h][$w] = 1;
      push(@res, "$h,$w");
    }
    $w++;
  }
}
my $tM;
my $maxv = 0;
foreach my $hw (@res) {
  my ($hs, $ws) = map {$_ + 0} split(/,/o, $hw);
  foreach my $h (0..$H-1) {
    foreach my $w (0..$W-1) {
      $tM->{$h}->{$w} = undef;
    }
  }
  my $cost = 0;
  $tM->{$hs}->{$ws} = $cost;
  &daisStep($hs, $ws, $cost);
  my $numcalc = 1;
  while ($numcalc) {
    $numcalc = 0;
    $cost++;
    foreach my $ht (keys %{$tM}) {
      foreach my $wt (keys %{$tM->{$ht}}) {
        if ( defined($tM->{$ht}->{$wt}) && $tM->{$ht}->{$wt} == $cost ) {
          &daisStep($ht, $wt, $cost);
          $numcalc++;
        }
      }
    }
  }
}
print $maxv,"\n";

sub daisStep($$$){
  my ($hi, $wi, $v) = @_;
  if ($hi+1 < $H && $M[$hi+1][$wi]) {
    if ( !defined($tM->{$hi+1}->{$wi}) || $tM->{$hi+1}->{$wi} > $v+1 ) {
        $tM->{$hi+1}->{$wi} = $v+1;
        $maxv = $v+1 if ( $maxv < $v+1 );
    }
  }
  if ($hi-1 >= 0 && $M[$hi-1][$wi]) {
    if ( !defined($tM->{$hi-1}->{$wi}) || $tM->{$hi-1}->{$wi} > $v+1 ) {
        $tM->{$hi-1}->{$wi} = $v+1;
        $maxv = $v+1 if ( $maxv < $v+1 );
    }
  }
  if ($wi+1 < $W && $M[$hi][$wi+1]) {
    if ( !defined($tM->{$hi}->{$wi+1}) || $tM->{$hi}->{$wi+1} > $v+1 ) {
        $tM->{$hi}->{$wi+1} = $v+1;
        $maxv = $v+1 if ( $maxv < $v+1 );
    }
  }
  if ($wi-1 >= 0 && $M[$hi][$wi-1]) {
    if ( !defined($tM->{$hi}->{$wi-1}) || $tM->{$hi}->{$wi-1} > $v+1 ) {
        $tM->{$hi}->{$wi-1} = $v+1;
        $maxv = $v+1 if ( $maxv < $v+1 );
    }
  }
}