h,w = map(int,input().split())
meiro = [list(input()) for i in range(h)]
max_d = 0
from collections import deque

def bfs(sx,sy,t_i,t_j):
    que = deque([(sx,sy)])
    INF= float('inf')
    d = [[INF]*w for i in range(h)]
    d[sx][sy] = 0
    while que:
        x,y =que.popleft()
        for dx,dy in [(0,1),(1,0),(-1,0),(0,-1)]:
            nx,ny = x+dx,y+dy
            if 0 <= nx < h and 0 <= ny < w and d[nx][ny] == INF and meiro[nx][ny] =='.':
                d[nx][ny] = d[x][y] +1
                que.append((nx,ny))
    return d[t_i][t_j] if d[t_i][t_j] != float('inf') else 0

for s_i in range(h):
    for s_j in range(w):
        for t_i in range(h):
            for t_j in range(w):
                if not (s_i == t_i and s_j == t_j):
                    max_d = max(bfs(s_i,s_j,t_i,t_j), max_d)
print(max_d)