from collections import deque

h,w = map(int,input().split())
s = [input() for i in range(h)]
sy,sx = 0,0
f = False
for i,si in enumerate(s):
    if f:
        break
    for j,sij in enumerate(si):
        if sij == ".":
            sysx = i,j
            f = True
            break

t = ((0,1),(1,0),(-1,0),(0,-1))
c = 0
se = set()
m = 0
for sy in range(h):
    for sx in range(w):
        if s[sy][sx] == "#":
            continue
        q = deque([(0,sy,sx)])
        max_cost = 0
        my,mx = 0,0
        f = [[True]*w for i in range(h)]
        f[sy][sx] = False
        while(q):
            cost,y,x = q.popleft()
            if max_cost < cost:
                max_cost = cost
                my,mx = y,x
            f[y][x] = False
            cost += 1
            for i,j in t:
                ny = y+i
                nx = x+j
                if 0 <= ny < h and 0 <= nx < w:
                    if s[ny][nx] == "." and f[ny][nx]:
                        q.append((cost,ny,nx))
        m = max(m,max_cost)
print(m)