import copy
h, w = map(int ,input().split())
maze = []
for i in range(h):
    maze.append(list(input()))
step = copy.deepcopy(maze)

def bfs(sx,sy,gx,gy):
    for i in range(h):
        for j in range(w):
            step[i][j] = 0
    dx = [0,0,-1,1]
    dy = [1,-1,0,0]
    que = []
    que.append([sx,sy])

    while(len(que) != 0):
        x, y = que[0][0], que[0][1]
        que.remove(que[0])
        if(x == gx and y == gy):
            return step[gy][gx]
        for i in range(4):
            nx, ny = x + dx[i], y + dy[i]
            if(0 <= nx < w and 0 <= ny < h):
                if(step[ny][nx] == 0 and maze[ny][nx] != "#"):
                    step[ny][nx] = step[y][x] + 1
                    que.append([nx, ny])
    
ans = 0
for i in range(h):
    for j in range(w):
        for k in range(h):
            for l in range(w):
                if(maze[i][j] == "." and maze[k][l] == "."):
                    ans = max(ans, bfs(j, i, l, k))
print(ans)
        