import copy
from collections import deque

h,w = map(int,input().split())

field = [['#']*(w+2)]
for _ in range(h):
    field.append(['#']+list(input())+['#'])
field.append(['#']*(w+2))
max_move = 0

for a in range(1,h+1):
    for b in range(1,w+1):
        maze = copy.deepcopy(field)
        qx,qy = deque(),deque()
        qx.append(a)
        qy.append(b)
        maze[a][b] = 0
        
        while True:
            if len(qy) == 0:
                break

            nx,ny = qx.popleft(),qy.popleft()
            dir_x,dir_y = [1,-1,0,0],[0,0,1,-1]
            for i in range(4):
                if maze[nx+dir_x[i]][ny+dir_y[i]] == '.':
                    maze[nx+dir_x[i]][ny+dir_y[i]] = maze[nx][ny]+1
                    qx.append(nx+dir_x[i])
                    qy.append(ny+dir_y[i])
            
        move=0
        for i in range(1,h+1):
            for j in range(1,w+1):
                if maze[i][j]!='#':
                    move = max(move,maze[i][j])
        
        max_move = max(move,max_move)

print(max_move)