# coding: utf-8
import queue
inf = 1000
di = [-1,0,1,0]
dj = [0,-1,0,1]
ans = 0
def update(i,j,x,f):
    if f[i][j] != inf:
        f[i][j] = x
h,w = [int(x) for x in input().split(" ")]
field = []
for i in range(h):
    field.append(input())
for i in range(h):
    for j in range(w):
        if field[i][j] == "#":
            continue
        q = queue.Queue()
        f = [[inf for k in range(w)] for l in range(h)]
        q.put([i,j])
        while not q.empty():
            i2,j2 = q.get()
            for m in range(4):
                ni=i2+di[m]
                nj=j2+dj[m]
                if ni<0 or ni>=h or nj<0 or nj>=w:
                    continue
                update(ni,nj,1,f)
                q.put([ni,nj])
        for i in range(h):
            for j in range(w):
                ans = max(ans, f[i][j])
print(ans)