import copy
h,w=map(int,input().split())
maze=[list(input()) for _ in range(h)]
df=[(1,0),(-1,0),(0,1),(0,-1)]
ans=0
for a in range(h):
  for b in range(w):
    if maze[a][b]=='#':
        continue
    for c in range(h):
      for d in range(w):
        if a==c and b==d:
          continue
        pos=[[a,b,0]]
        meiro=copy.deepcopy(maze)
        while len(pos):
          x,y,depth=pos.pop(0)
          if x==c and y==d:
            ans=max(ans,depth)
            break
          meiro[x][y]='#'
          for dx,dy in df:
            if 0<=x+dx<h and 0<=y+dy<w and meiro[x+dx][y+dy]=='.':
                pos.append([x+dx,y+dy,depth+1])
print(ans)