import numpy as np
import queue
H, W = map(int, input().split())
S = [input() for _ in range(H)]
reach = [[False] * W for i in range(H)]
step = np.ones((H, W)) * (-1)
m = 0
q = queue.Queue()

for sh in range(H):
    for sw in range(W):
        if S[sh][sw] == '#':
            pass
        elif (sh - 1 >= 0 and S[sh -1][sw] != '#') and  (sh + 1 < H and S[sh +1][sw] != '#'):
            pass
        elif (sw - 1 >= 0 and S[sh][sw-1] != '#') and  (sw + 1 < W and S[sh][sw + 1] != '#'):
            pass
        else:
            reach = [[False] * W for i in range(H)]
            step = np.ones((H, W)) * (-1)
            #dfs(sw, sh, 0)
            q.put((sw, sh, 0))
            while not q.empty():
                x, y, s = q.get()
                if x < 0 or W <= x or y < 0 or H <= y:
                    pass
                elif reach[y][x]:
                    pass
                elif S[y][x] == '#':
                    pass
                else:
                    reach[y][x] = True
                    step[y, x] = min(s, step[y, x]) if step[y, x] != -1 else s

                    q.put((x+1, y, s+1))
                    q.put((x-1, y, s+1))
                    q.put((x, y-1, s+1))
                    q.put((x, y+1, s+1))

            m = max(m, np.max(step))

print(int(m))
