from collections import deque
from itertools import product
from copy import deepcopy

h, w = map(int, input().split())
ls = [list(input()) for _ in range(h)]

sls = list(product(range(h),range(w)))
gls = list(product(range(h),range(w)))
ans = 0
move = [[0,1], [1,0],[0,-1], [-1,0]]
for s in sls:
    for g in gls:
        if s==g or ls[s[0]][s[1]] == '#' or ls[g[0]][g[1]] == '#' :
            continue
        else:
            lss = deepcopy(ls)
            d=deque()
            d.append(s)
            lss[s[0]][s[1]] = 0
            while d:
                x,y = d.popleft()
                c = lss[x][y]
                for dx,dy in move:
                    if 0<=x+dx<h and 0<=y+dy<w and lss[x+dx][y+dy] == '.' :
                        lss[x+dx][y+dy] = c+1
                        d.append([x+dx, y+dy])
            ans = max(ans, lss[g[0]][g[1]])

print(ans)
