/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/* libnum {{{*/
void amax(N, Args...)(ref N x, Args y) {
  x = x.max(y);
}
void amin(N, Args...)(ref N x, Args y) {
  x = x.min(y);
}
auto maxE(R)(R r) if (isInputRange!R) {
  ElementType!R x = r.front;
  r.popFront();
  foreach (y; r) x.amax(y);
  return x;
}
auto minE(R)(R r) if (isInputRange!R) {
  ElementType!R x = r.front;
  r.popFront();
  foreach (y; r) x.amin(y);
  return x;
}
/*}}}*/


/+---test
3 3
...
...
...
---+/

/+---test
3 5
...#.
.#.#.
.#...
---+/

enum long INF = 100000000;

void main(string[] args) {
  long H, W;
  readf(" %d %d ", &H, &W);

  auto S = new bool[][](H);
  foreach (ref s; S) {
    s = readln.map!(c => c == '.').array;
  }

  auto dist = new long[][](H*W, H*W);
  foreach (ref d; dist) d[] = INF;

  foreach (y; 0..H) foreach (x; 0..W) {
    if (!S[y][x]) continue;
    dist[y*W+x][y*W+x] = 0;
    if (y && S[y-1][x]) {
      dist[y*W+x][y*W-W+x] = 1;
    }
    if (x && S[y][x-1]) {
      dist[y*W+x][y*W+x-1] = 1;
    }
    if (y+1 < H && S[y+1][x]) {
      dist[y*W+x][y*W+W+x] = 1;
    }
    if (x+1 < W && S[y][x+1]) {
      dist[y*W+x][y*W+x+1] = 1;
    }
  }
  foreach (y1; 0..H) foreach (x1; 0..W) foreach (y2; 0..H) foreach (x2; 0..W) foreach (y3; 0..H) foreach (x3; 0..W) {
    dist[y2*W+x2][y3*W+x3].amin(dist[y2*W+x2][y1*W+x1] + dist[y1*W+x1][y3*W+x3]);
  }

  long ans;
  foreach (i; 0..H*W) foreach (j; 0..H*W) {
    if (dist[i][j] < INF) ans.amax(dist[i][j]);
  }
  ans.writeln;
}
