from collections import deque
import sys
buf = sys.stdin.buffer

h, w = map(int, buf.readline().split())
map = ""
for _ in range(h):
    map += input() + "#"
#print(map)

n = h * (w + 1)
periods = [[] for _ in range(n)]
dir = [-w - 1, 1, -1, w + 1]
for i in range(n):
    if map[i] == "#":
        continue
    for d in dir:
        next_i = i + d
        if next_i < 0 or next_i >= n or map[next_i] == "#":
            continue
        periods[i].append(next_i)
#print(periods)

q = deque()
def bfs(pos):
    for next_i in periods[pos]:
        if con_cnt[next_i] == -1:
            con_cnt[next_i] = con_cnt[pos] + 1
            q.append(next_i)
        #まだスタックが残っている場合、左から抜き出す
        if len(q) > 0:
            bfs(q.popleft())

start_points = [i for i, j in enumerate(periods) if len(j) > 0]
ans = 0
for start_point in start_points:
    con_cnt = [-1] * n
    con_cnt[start_point] = 0
    bfs(start_point)
    ans = max(ans, max(con_cnt))
print(ans)