from collections import defaultdict as dd, deque

h,w = map(int,input().split())
M = [input().strip()+'#' for _ in range(h)]
M.append(w*'#')

road = []

start = None
for i in range(h):
    for j in range(w):
        if M[i][j] == '.':
            road.append((j,i))

def dist(aa,bb,cc,dd):
    Q = deque()
    Q.append((0, aa, bb))
    seen = set()
    while Q:
        d,x,y = Q.popleft()

        if (x,y) == (cc,dd):
            return d
        if (x,y) in seen: continue
        seen.add((x,y))

        for nx,ny in [(x+1,y), (x-1,y), (x,y+1), (x,y-1)]:
            if M[ny][nx] == '.':
                Q.append((d+1, nx, ny))

    raise AssertionError('D:')


print(max(dist(a[0], a[1], b[0], b[1]) for a in road for b in road))
