import queue
import copy

def sgmake(lst):
    for i in range(H):
        for j in range(W):
            if i != j:
                lst.append((i, j))

def bfs(s1,s2, g1, g2):
    cs = copy.deepcopy(s)
    cs[g1][g2] = 'g'
    queueX = queue.Queue()
    queueY = queue.Queue()
    queueX.put(s1)
    queueY.put(s2)
    cs[s1][s2] = 0
    gx = 'Fail'
    gy = 'Fail'
    while queueX.empty() == False:
        x = queueX.get()
        y = queueY.get()

        for i in range(4):
            nextX = x + moveR[i]
            nextY = y + moveC[i]
            if 0 <= nextX and nextX < H\
                and 0 <= nextY and nextY < W\
                and cs[nextX][nextY] != '#'\
                and cs[nextX][nextY] == '.':
                cs[nextX][nextY] = cs[x][y] + 1
                queueX.put(nextX)
                queueY.put(nextY)

            if 0 <= nextX and nextX < H\
                and 0 <= nextY and nextY < W\
                and cs[nextX][nextY] == 'g':
                cs[nextX][nextY] = cs[x][y] + 1
                gx = nextX
                gy = nextY

    if gx != False:
        return cs[gx][gy]
    else:
        return 0

H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]

moveR = [0, 1, -1, 0]
moveC = [1, 0, 0, -1]
ans = 0
slst = []
glst = []
sgmake(slst)
sgmake(glst)
for i in slst:
    for j in glst:
        if i != j:
            if s[i[0]][i[1]] != '#' and s[j[0]][j[1]] != '#':
                tmp = bfs(i[0], i[1], j[0], j[1])
                ans = max(ans, tmp)

print(ans)