#-- ワーシャルフロイド解 --#
from strutils import split, parseInt
from sequtils import map, newSeqWith, mapIt

const
  ds = @[(x: -1, y: 0), (x: 1, y: 0), (x: 0, y: -1), (x: 0, y: 1)]
  INF = int.high div 2

# 入力
var H, W: int
(H, W) = stdin.readLine.split.map(parseInt)
let S = newSeqWith(H, stdin.readLine)

# グラフの構築
var graph = newSeqWith(H * W, newSeqWith(H * W, INF))
for y in 0..<H:
  for x in 0..<W:
    if S[y][x] != '.': continue
    for d in ds:
      let next = (x: x + d.x, y: y + d.y)
      let (a, b) = (y * W + x, next.y * W + next.x) # (x, y) を一次元に圧縮
      graph[a][a] = 0
      if next.x in 0..<W and next.y 0..< H and S[next.y][next.x] == '.':
        if graph[a][b] > 1: graph[a][b] = 1
        if graph[b][a] > 1: graph[b][a] = 1

# ワーシャルフロイド
for k in 0..<(H * W):
  for i in 0..<(H * W):
    for j in 0..<(H * W):
      graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j])

# 距離が INF で，到達できない部分の距離は -1 としておく
for i, _ in graph:
  for j, distance in graph[i]:
    if distance == INF:
      graph[i][j] = -1

# 距離の最大値が答え
echo graph.mapIt(it.max).max
