import strutils,sequtils
import algorithm,sets,lists,critbits,sequtils,intsets,strutils,tables,math,heapqueue,future

let read = iterator: string {.closure.} =
  while true:
    for s in stdin.readLine.split:
      yield s

let H, W = read().parseInt
var maze = newSeq[seq[char]]()

for _ in 1..H:
  maze.add(lc[x | (x <- stdin.readLine), char])

let vs = [(0, 1), (0, -1), (1, 0), (-1, 0)]
proc bfs(i: int, j: int): int =
  var
    visited = initHashSet[(int, int)]()
    q = initHeapQueue[(int, int, int)]()
  q.push((0, i, j))

  while q.len > 0:
    let (cnt, i1, j1) = q.pop()
    visited.incl((i1, j1))
    if maze[i1][j1] == '#':
      continue
    result = max(cnt, result)
    for v in vs:
      let
        i2 = i1 + v[0]
        j2 = j1 + v[1]
      if i2 < 0 or i2 >= H:
        continue
      if j2 < 0 or j2 >= W:
        continue
      if maze[i2][j2] == '#':
        continue
      if visited.contains((i2, j2)):
        continue
      q.push((cnt+1, i2, j2))

var ans = 0
for i in 0..<H:
  for j in 0..<W:
    if maze[i][j] != '#':
      ans = max(ans, bfs(i, j))
echo ans
