import queue

h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]

q = queue.Queue()
def bfs(x, y, cnt):
    if 0 <= x and x < w and 0 <= y and y < h and s[y][x] == "." and t[y][x] == ".":
        t[y][x] = cnt
        cnt += 1
        q.put((x, y))
        x, y = q.get()
        bfs(x+1, y, cnt)
        bfs(x-1, y, cnt)
        bfs(x, y+1, cnt)
        bfs(x, y-1, cnt)
        ans.append(cnt-1)
        
ans = []
for i in range(h):
    for j in range(w):
        t = [["."]*w for _ in range(h)]
        bfs(j, i, 0)

print(max(ans))