import sys
from collections import deque

def main():
    h, w = map(int, input().split())
    maze = [input() for i in range(h)]
    # 行ったかどうかのフラグ
    visited = [[-1]*w for j in range(h)]
    sg = []
    for i in range(h):
        for j in range(w):
            if maze[i][j] == '.':
                sy = i
                sx = j
                for k in range(h):
                    for l in range(w):
                        if maze[i][j] == '.' and (k != i and l != j):
                            gy = k
                            gx = l
                            sg.append([sy, sx, gy, gx])

    # 移動パターン
    mv = [[1, 0], [-1, 0], [0, 1], [0, -1]]
    ans = 0
    #for sy, sx, gy, gx in [[0, 0, h-1, w-1]]:
    for sy, sx, gy, gx in sg:
        visited = [[-1]*w for j in range(h)]
        q = deque([[sy, sx]])
        visited[sy][sx] = 0 
        while q:
            y, x = q.popleft()
            if y == gy and x == gx:
                ans = max(ans, visited[y][x])
                break
            for i, j in mv:
                if (0 <= y + i < h) and (0 <= x + j < w):  
                    ny = y+i
                    nx = x+j
                    if visited[ny][nx] != -1:
                        continue
                    if maze[ny][nx] == '.':
                        visited[ny][nx] = visited[y][x] + 1 
                        q.append([ny, nx])
                else:
                    continue
    print(ans)

if __name__ == '__main__':
    main()