from collections import deque
import math

H,W = list(map(int,input().split()))
r = []
ans = []
for i in range(H):
    S = str(input())
    S = [S[i] for i in range(len(S))]
    r.append(S)

def mazesol(H,W,r,sx,sy,ans):
    count = 0
    bfs = [[-1 for i in range(W+2)] for j in range(H+2)]
    for i in range(H):
        for j in range(W):
            if r[i][j] == '.':
                bfs[i+1][j+1] = math.inf
    if bfs[sy-1][sx-1] != -1:
        bfs[sy-1][sx-1] = 0
        que = deque([[sy-1,sx-1]])
        while que:
            y,x = que.popleft()
            for i,j in [(1,0),(0,1),(-1,0),(0,-1)]:
                ny,nx = y+i,x+j
                nex = bfs[ny][nx]
                if nex != '#':
                    if nex > bfs[y][x]+1:
                        bfs[ny][nx]=bfs[y][x]+1
                        que.append([ny,nx])
        for i in range(W+2):
            ans.append(max(bfs[i]))
for i in range(H+2):
    for j in range(W+2):
        mazesol(H,W,r,j,i,ans)
print(max(ans))