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 = 0
for v, d in D.items():
    if d > md:
        md = d
        mv = v
D = defaultdict(default)
q = PriorityQueue(H*W)
q.put((0, mv))
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))
for v, d in D.items():
    if d > md:
        md = d
        mv = v
print(md)
