from collections import deque
import numpy as np
def main():
    hw = list(map(int, input().split()))
    s = np.zeros((hw[0],hw[1]), dtype=int)
    validpoints = []
    for i in range(hw[0]):
        tmp = input()
        tm = [None]*hw[1]
        for j in range(hw[1]):
            if tmp[j] == '.':
                tm[j] = 0
                validpoints.append((i,j))
            elif tmp[j] == '#':
                tm[j] = 1
        s[i] = np.array(tm)

    ma = 0
    for i in validpoints:
        for j in validpoints:
            cost = breadth(s,i,j)
            if cost > ma:
                ma = cost
    print(ma)

    # print(breadth(s,(2,0),(0,4)))
    # print(breadth(s,(0,0),(2,2)))
    
def breadth(ss, start, goal):
    q = deque()
    visited = np.array(ss)
    visited[start] = 1
    q.append(start)
    c = 0
    while not len(q) == 0:
        v = q.pop()
        if v == goal:
            break
        down = (v[0]+1,v[1])
        up = (v[0]-1,v[1])
        right = (v[0],v[1]+1)
        left = (v[0],v[1]-1)
        child = [down,up,right,left]
        child = list(filter(lambda i: 0 <= i[0] < len(ss) and 0 <= i[1] < len(ss[0]) and visited[i[0],i[1]] == 0, child))

        for i in child:
            visited[i] = 1
            q.append(i)
        c += 1
        
    return c

if __name__ == '__main__':
    main()