# すべてのスタートを試し、最大値の最大値を取る



import sys

readline = sys.stdin.readline



H,W = list(map(int,readline().split()))

grid = [readline().rstrip() for i in range(H)]



ans = 0

cases = ((0,1),(0,-1),(1,0),(-1,0))

from collections import deque

for i in range(H):

  for j in range(W):

    q = deque([[i,j,0]])

    visited = [[False] * W for i in range(H)]

    while q:

      y,x,d = q.popleft()

      if grid[y][x] == "#":

        continue

      if visited[y][x]:

        continue

      visited[y][x] = True

      if d > ans:

        ans = d

      for c in cases:

        if 0 <= y + c[0] < H and 0 <= x + c[1] < W:

          q.append([y + c[0],x + c[1],d + 1])

print(ans)
import sys

readline = sys.stdin.readline



H,W = list(map(int,readline().split()))

S = [None] * H

for i in range(H):

  S[i] = readline().rstrip()



ans = 0

from collections import deque

cases = ((1,0),(-1,0),(0,1),(0,-1))

for i in range(H):

  for j in range(W):

    q = deque([[i,j,0]])

    seen = set()

    while q:

      y,x,d = q.popleft()

      if S[y][x] == "#":

        continue

      if (y,x) in seen:

        continue

      seen.add((y,x))

      if d > ans:

        ans = d

      for c in cases:

        if 0 <= y + c[0] < H and 0 <= x + c[1] < W:

          q.append([y + c[0], x + c[1], d + 1])



print(ans)
# すべてのスタートを試し、最大値の最大値を取る
import sys

readline = sys.stdin.readline
H, W = list(map(int, readline().split()))
grid = [readline().rstrip() for i in range(H)]
ans = 0
cases = ((0, 1), (0, -1), (1, 0), (-1, 0))
from collections import deque

for i in range(H):
    for j in range(W):
        q = deque([[i, j, 0]])
        visited = [[False] * W for i in range(H)]
        while q:
            y, x, d = q.popleft()
            if grid[y][x] == "#":
                continue
            if visited[y][x]:
                continue
            visited[y][x] = True
            if d > ans:
                ans = d
            for c in cases:
                if 0 <= y + c[0] < H and 0 <= x + c[1] < W:
                    q.append([y + c[0], x + c[1], d + 1])
print(ans)

import sys

readline = sys.stdin.readline
H, W = list(map(int, readline().split()))
S = [None] * H
for i in range(H):
    S[i] = readline().rstrip()
ans = 0
from collections import deque

cases = ((1, 0), (-1, 0), (0, 1), (0, -1))
for i in range(H):
    for j in range(W):
        q = deque([[i, j, 0]])
        seen = set()
        while q:
            y, x, d = q.popleft()
            if S[y][x] == "#":
                continue
            if (y, x) in seen:
                continue
            seen.add((y, x))
            if d > ans:
                ans = d
            for c in cases:
                if 0 <= y + c[0] < H and 0 <= x + c[1] < W:
                    q.append([y + c[0], x + c[1], d + 1])
print(ans)

-# すべてのスタートを試し、最大値の最大値を取る -grid = [readline().rstrip() for i in range(H)] +S = [None] * H +for i in range(H): +    S[i] = readline().rstrip() -cases = ((0, 1), (0, -1), (1, 0), (-1, 0)) +cases = ((1, 0), (-1, 0), (0, 1), (0, -1)) -        visited = [[False] * W for i in range(H)] +        seen = set() -            if grid[y][x] == "#": +            if S[y][x] == "#": -            if visited[y][x]: +            if (y, x) in seen: -            visited[y][x] = True +            seen.add((y, x))