from collections import defaultdict


class Graph():
    def __init__(self):
        self.value = defaultdict(list)
        self.res = {}

    def addConnection(self, parent, child):
        self.value[parent].append(child)

    def addWays(self, node):
        for item in node:
            self.res[item] = 0

    def BFS(self, start, goal):
        visited = [start]
        queue = [start]
        while queue:
            x = queue.pop(0)
            # print(x, end=" ")
            for item in self.value[x]:
                if item not in visited:
                    queue.append(item)
                    visited.append(item)
                    self.res[item] = self.res[x] + 1
        if not self.res:
            return 0
        return self.res[goal]


h, w = list(map(int, input().split()))
s = [["#" for _ in range(w + 2)]]
for _ in range(h):
    s.append(["#"] + list(input()) + ["#"])
s.append(["#" for _ in range(w + 2)])
node = [i for i in range((h + 2) * (w + 2))]
size = len(node)
g_list = [Graph() for _ in node]
for ii in range(1, h + 1):
    for jj in range(1, w + 1):
        convd_index = ii * (w + 2) + jj
        g_list[convd_index].addWays(node)
        for i in range(1, h + 1):
            for j in range(1, w + 1):
                convd = i * (w + 2) + j
                if s[i + 1][j] == ".":
                    g_list[convd_index].addConnection(
                        convd, ((i + 1) * (w + 2) + j))
                if s[i - 1][j] == ".":
                    g_list[convd_index].addConnection(
                        convd, ((i - 1) * (w + 2) + j))
                if s[i][j + 1] == ".":
                    g_list[convd_index].addConnection(
                        convd, (i * (w + 2) + j + 1))
                if s[i][j - 1] == ".":
                    g_list[convd_index].addConnection(
                        convd, (i * (w + 2) + j - 1))
res = 0
for start in range(size):
    for goal in range(size):
        if start == goal:
            continue
        bfs = g_list[start].BFS(start, goal)
        if bfs > res:
            res = bfs
print(res)
