import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    inf=1000
    h,w=MI()
    ss=[[c=="#" for c in input()] for _ in range(h)]
    n=h*w
    dist=[[inf]*n for _ in range(n)]
    #for i in range(n):dist[i][i]=0
    to=defaultdict(list)
    kill=[False]
    for i in range(h):
        for j in range(w):
            if ss[i][j]:continue
            ij=w*i+j
            for ni,nj in [(i+1,j),(i,j+1),(i-1,j),(i,j-1)]:
                if ni<0 or nj<0 or ni>=h or nj>=w:continue
                if ss[ni][nj]:continue
                nij=w*ni+nj
                to[ij].append(nij)
                to[nij].append(ij)
                dist[nij][ij]=dist[ij][nij]=1
    for j in range(n):
        for i in range(n):
            for k in range(n):
                d=dist[i][j]+dist[j][k]
                if d>=inf:continue
                if d<dist[i][k]:dist[i][k]=d
    #p2D(dist)
    mx=0
    for i in range(n):
        for j in range(n):
            d=dist[i][j]
            if d==inf:continue
            if d>mx:mx=d
    print(mx)

main()