import sys
sys.setrecursionlimit(1000000)
from collections import deque


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

def bfs(sx,sy,gx,gy):
    dx = [0,1,0,-1]
    dy = [1,0,-1,0]
    d = [[float('inf')]*w for i in range(h)]
    q = deque()
    q.append((sx,sy))
    d[sx][sy] = 0
    while q:
        x,y = q.popleft()
        if x == gx and y == gy:
            break
        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]
            if  0<= nx < h and 0 <= ny < w and d[nx][ny]==float('inf') and s[nx][ny]=='.':
                q.append((nx,ny))
                d[nx][ny] = d[x][y]+1
    return d[gx][gy]

count = 0
for i in range(h):
    for j in range(w):
        for k in range(h):
            for l in range(w):
                if s[i][j] != '#' and s[k][l] != '#':
                    count  = max(count, bfs(i,j,k,l))
print(count)