import queue
import copy

def replace(s, n, c):
    if n < 0 or n >= len(s):
        return s
    return s[:n]+c[0]+s[n+1:]

h, w = map(int, input().split())
l = [input() for _ in range(h)]

def dist(m, x1, y1, x2, y2):
    q = queue.Queue()
    q.put((x1, y1, 0))
    while not q.empty():
        x, y, count = q.get()
        if (x, y) == (x2, y2):
            return count
        if x > 0 and m[y][x-1] == ".":
            m[y] = replace(m[y], x-1, "#")
            q.put((x-1, y, count+1))
        if y > 0 and m[y-1][x] == ".":
            m[y-1] = replace(m[y-1], x, "#")
            q.put((x, y-1, count+1))
        if x < w-1 and m[y][x+1] == ".":
            m[y] = replace(m[y], x+1, "#")
            q.put((x+1, y, count+1))
        if y < h-1 and m[y+1][x] == ".":
            m[y+1] = replace(m[y+1], x, "#")
            q.put((x, y+1, count+1))

ans = 0
for i in range(h):
    for j in range(w):
        for _i in range(h):
            for _j in range(w):
                if l[i][j] == "." and l[_i][_j] == ".":
                    ans = max(ans, dist(copy.copy(l), j, i, _j, _i))
print(ans)