import sys
from collections import deque
input = sys.stdin.readline

H, W = map(int,input().split())

maze_array = [input().split()[0] for _ in range(H)]

ans = 0
for hh in range(H):
    for ww in range(W):
        flag = [[0 for _ in range(W)] for _ in range(H)]
        queue = deque()
        queue.append((hh,ww,0))
        flag[hh][ww] = 1
        while len(queue):
            h, w, p = queue.popleft()
            # print(h,w,p)
            if w != W - 1 and flag[h][w+1] == 0 and maze_array[h][w+1] == ".":
                flag[h][w+1] = 1
                ans = max(ans,p+1)
                queue.append((h,w+1,p+1))
            if h != H - 1 and flag[h+1][w] == 0 and maze_array[h+1][w] == ".":
                flag[h+1][w] = 1
                ans = max(ans,p+1)
                queue.append((h+1,w,p+1))
            if w != 0 and flag[h][w-1] == 0 and maze_array[h][w-1] == ".":
                flag[h][w-1] = 1
                ans = max(ans,p+1)
                queue.append((h,w-1,p+1))  
            if h != 0 and flag[h-1][w] == 0 and maze_array[h-1][w] == ".":
                flag[h-1][w] = 1
                ans = max(ans,p+1)
                queue.append((h-1,w,p+1))
print(ans) 
             