from collections import defaultdict
from queue import PriorityQueue
H, W = map(int, input().split())
M = []
for h in range(H):
    M.append(input()+'#')
M.append('#'*(W+1))

INF = 10000
def default():
    return INF
neighbor = defaultdict(list)
for h in range(H):
    for w in range(W):
        if M[h][w] == '#':
            continue
        u = (h, w)
        if M[h+1][w] == '.':
            v = (h+1, w) 
            neighbor[u].append(v)
            neighbor[v].append(u)
        if M[h][w+1] == '.':
            v = (h, w+1)
            neighbor[u].append(v)
            neighbor[v].append(u)
D = defaultdict(default)
q = PriorityQueue(H*W)
s = u
q.put((0, s))
while not q.empty():
    d, u = q.get()
    for v in neighbor[u]:
        if D[v] > d+1:
            D[v] = d+1
            q.put((d+1, v))
md = max(D.values())
mu = [u for u, d in D.items() if d == md]
answer = 0

for u in mu:
    D = defaultdict(default)
    q = PriorityQueue(H*W)
    q.put((0, u))
    while not q.empty():
        d, u = q.get()
        for v in neighbor[u]:
            if D[v] > d+1:
                D[v] = d+1
                q.put((d+1, v))
                answer = max(d+1, answer)
print(answer)
