def main():    
    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
          pos=[[a,b,0]]
          meiro=copy.deepcopy(maze)
          while len(pos):
            x,y,depth=pos.pop(0)
            ans=max(ans,depth)
            meiro[x][y]='#'
            flag=False
            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])
                  flag=True
            if flag==False:
              break
    print(ans)
main()