# 2020/01/12

from copy import deepcopy
import sys
from collections import deque

sys.setrecursionlimit(10**7)

dr=[(-1,0),(0,-1),(0,1),(1,0)]

h,w=map(int,input().split())
g=[list('#')*(w+2)]
for _ in range(h):
    g+=[['#']+list(input())+['#']]
g+=[list('#')*(w+2)]

# visited=[list([1]*(w+2))]
# for _ in range(h):
#     visited+=[[1]+list([0]*w)+[1]]
# visited+=[list([1]*(w+2))]


def bfs(sx,sy,maze):
    res=0
    x,y=sx,sy
    maze[x][y]=0
    que=deque()
    que.append((x,y))

    while que:
        x,y=que.popleft()
        for dx,dy in dr:
            nx=dx+x
            ny=dy+y
            if maze[nx][ny]!='@':continue
            maze[nx][ny]=maze[x][y]+1
            que.append((nx,ny))
            res=max(res,maze[nx][ny])
    return res


def find(mz):
    maze=deepcopy(mz)
    ret=0
    for i in range(1,h+1):
        for j in range(1,w+1):
            if maze[i][j]!='@':continue
            res=bfs(i,j,maze)
            ret=max(res,ret)
            maze=deepcopy(mz)

    return ret


def mk_maze(sx,sy,maze):
    x,y=sx,sy
    maze[x][y]='@'
    que=deque()
    que.append((x,y))

    while que:
        x,y=que.popleft()
        g[x][y]='#'
        for dx,dy in dr:
            nx=dx+x
            ny=dy+y
            if g[nx][ny]=='#':continue
            maze[nx][ny]='@'
            que.append((nx,ny))
    return maze

maze=[[0]*(w+2) for _ in range(h+2)]
ans=0
for i in range(1,h+1):
    for j in range(1,w+1):
        if g[i][j]=='#':continue
        mz=mk_maze(i,j,maze)
        res=find(mz)
        ans=max(res,ans)
print(res)