import numpy as np
from collections import deque

def resolve():
    H, W = map(int, input().split())

    maze = []
    for i in range(H):
        maze.append(input())

    def dfs(st):

        INF = -1
        d = np.full((H, W), INF)

        dx = [1, 0, -1, 0]
        dy = [0, 1, 0, -1]

        que = deque()
        que.append(st)
        d[st[1]][st[0]] = 0

        while len(que):
            p = que.popleft()
            # print(p)

            for i in range(4):
                nx = p[0] + dx[i]
                ny = p[1] + dy[i]

                if nx >= 0 and nx < W and ny >= 0 and ny < H and maze[ny][nx] != "#" and d[ny][nx] == INF:
                    # print("next is ", nx, ny)
                    que.append([nx, ny])
                    d[ny][nx] = d[p[1]][p[0]] + 1
                    # print(d)
                    # print(que)

        cost = np.max(d)
        idx = np.unravel_index(np.argmax(d), d.shape)
        # print(idx)
        # print(cost)
        return idx, cost

    max_cost = 0
    for y in range(H):
        for x in range(W):
            if maze[y][x] == '.':
                st = [x, y]
                idx, cost = dfs(st)
                if cost > max_cost:
                    max_cost = cost 
        break
    
    # idx, cost = dfs(st)
    # idx, cost = dfs((idx[1], idx[0]))
    print(int(max_cost))

if __name__ == "__main__":
    resolve()