import queue
import copy

def ngoin(bo,now):
    return 0 <= now[0] and now[0] < len(bo) and 0 <= now[1] and now[1] < len(bo[0])

def minido(bo,si,sj,ei,ej):
    tb = [[False for i in range(len(bo[0]))] for j in range(len(bo))]
    q = queue.Queue()
    q.put([si,sj,0])
    while not q.empty():
        now = q.get()
        if now[0] == ei and now[1] == ej:
            return now[2]
        if tb[now[0]][now[1]]:
            continue
        tb[now[0]][now[1]] = True
        if ngoin(bo,[now[0]-1,now[1]]):
            if bo[now[0]-1][now[1]]:
                q.put([now[0]-1,now[1],now[2]+1])
        if ngoin(bo,[now[0],now[1]+1]):
            if bo[now[0]][now[1]+1]:
                q.put([now[0],now[1]+1,now[2]+1])
        if ngoin(bo,[now[0]+1,now[1]]):
            if bo[now[0]+1][now[1]]:
                q.put([now[0]+1,now[1],now[2]+1])
        if ngoin(bo,[now[0],now[1]-1]):
            if bo[now[0]][now[1]-1]:
                q.put([now[0],now[1]-1,now[2]+1])
            
            

h,w = map(int,input().split())
board = [[True if x == '.' else False for x in input()] for i in range(h)]
ans = 0
for si in range(h):
    for sj in range(w):
        for ei in range(h):
            for ej in range(w):
                if (not board[si][sj]) or (not board[ei][ej]):
                    continue
                ans = max(ans,minido(board,si,sj,ei,ej))
print(ans)