use v5.18; # strict say state
use warnings;
use List::Util qw(reduce first max min sum0);

my ($h, $w) = split / /, <STDIN>;
my @s;
{
  for (my $i=0; $i<$h+2; $i++) {
    my @b;
    for (my $j=0; $j<$w+2; $j++) {
      if ($i==0 || $j==0 || $i==$h+1 || $j==$w+1) {;
        push  @b, '#';
      } else {
        push @b, 0;
      }
    }
    $s[$i] = \@b;
  }
}
for my $i (1..$h) {
  chomp (my $in = <STDIN>);
  my @b = split //, $in;
  for my $j (1..$w) {
    $s[$i][$j] = $b[$j-1];
  }
}
my $d = 0;
for (my $i=0; $i<$h+2; $i++) {
  for (my $j=0; $j<$w+2; $j++) {
    if ($s[$i][$j] eq '.') {
      $d++;
    }
  }
}
sub count {
  my $t = shift;
  my $c = 0;
  my $max = 0;
  while ($c<$d-1) {
    for my $i (1..$h+1) {
      for my $j (1..$w+1) {
        if ($$t[$i][$j]<1 && $s[$i][$j] eq '.') {
          my $e = min grep{$_>0} ($$t[$i-1][$j], $$t[$i+1][$j], $$t[$i][$j-1], $$t[$i][$j+1]);
          if ($e>0) {
            $e++;
            $$t[$i][$j] = $e;
            $max = $e if $max < $e;
            $c++;
          }
        }
      }
    }
  }
  return $max;
}
my $max = 0;
for my $i (1..$h+1) {
  for my $j (1..$w+1) {
    if ($s[$i][$j] eq '.') {
      my @t;
      $t[$i][$j] = 1;
      my $m = count(\@t);
      $max = $m if $max < $m;
    }
  }
}

say $max-1;