from collections import deque

import copy



def BFS(h,w,sy,sx,xy_list):

 dist=[[-1]*w for i in range(h)]

 dist[sy][sx]=0

 xy_list[sy][sx]='#'



 dq=deque()

 dq.append((sy,sx))



 while dq:

  y,x=dq.popleft()

  for dy,dx in [[1,0],[-1,0],[0,1],[0,-1]]:

   ny=y+dy

   nx=x+dx

   if 0<=ny<h and 0<=nx<w and xy_list[ny][nx]!='#':

    dq.append((ny,nx))

    xy_list[ny][nx]='#'

    dist[ny][nx]=dist[y][x]+1



 return dist



def main():

 h,w=list(map(int,input().split()))

 s=[list(eval(input())) for i in range(h)]



 ans=0

 for hh in range(h):

  for ww in range(w):

   if s[hh][ww]=='#':

    continue

   xy_list=copy.deepcopy(s)

   dist=BFS(h,w,hh,ww,xy_list)

   for d in dist:

    ans=max(ans,max(d))



 print(ans)



if __name__=="__main__":

  main()
from sys import stdin

nii=lambda:list(map(int,stdin.readline().split()))

lnii=lambda:list(map(int,stdin.readline().split()))

from copy import deepcopy

from collections import deque



h,w=nii()

s=[list(eval(input())) for i in range(h)]



def dfs(cs,i,j):

  que=deque()

  que.append([i,j])



  cs[i][j]='#'



  dist=[[-1 for a in range(w)] for b in range(h)]

  dist[i][j]=0



  while que:

    y,x=que.popleft()

    for dy,dx in [[1,0],[-1,0],[0,1],[0,-1]]:

      ny=y+dy

      nx=x+dx

      if 0<=ny<h and 0<=nx<w and cs[ny][nx]=='.':

        que.append([ny,nx])

        cs[ny][nx]='#'

        dist[ny][nx]=dist[y][x]+1



  t_ans=0

  for a in dist:

    t_ans=max(t_ans,max(a))



  return t_ans



ans=0

for i in range(h):

  for j in range(w):

    if s[i][j]=='.':

      cs=deepcopy(s)

      dist=dfs(cs,i,j)

      ans=max(ans,dist)



print(ans)
from collections import deque
import copy


def BFS(h, w, sy, sx, xy_list):
    dist = [[-1] * w for i in range(h)]
    dist[sy][sx] = 0
    xy_list[sy][sx] = "#"
    dq = deque()
    dq.append((sy, sx))
    while dq:
        y, x = dq.popleft()
        for dy, dx in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
            ny = y + dy
            nx = x + dx
            if 0 <= ny < h and 0 <= nx < w and xy_list[ny][nx] != "#":
                dq.append((ny, nx))
                xy_list[ny][nx] = "#"
                dist[ny][nx] = dist[y][x] + 1
    return dist


def main():
    h, w = list(map(int, input().split()))
    s = [list(eval(input())) for i in range(h)]
    ans = 0
    for hh in range(h):
        for ww in range(w):
            if s[hh][ww] == "#":
                continue
            xy_list = copy.deepcopy(s)
            dist = BFS(h, w, hh, ww, xy_list)
            for d in dist:
                ans = max(ans, max(d))
    print(ans)


if __name__ == "__main__":
    main()

from sys import stdin

nii = lambda: list(map(int, stdin.readline().split()))
lnii = lambda: list(map(int, stdin.readline().split()))
from copy import deepcopy
from collections import deque

h, w = nii()
s = [list(eval(input())) for i in range(h)]


def dfs(cs, i, j):
    que = deque()
    que.append([i, j])
    cs[i][j] = "#"
    dist = [[-1 for a in range(w)] for b in range(h)]
    dist[i][j] = 0
    while que:
        y, x = que.popleft()
        for dy, dx in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
            ny = y + dy
            nx = x + dx
            if 0 <= ny < h and 0 <= nx < w and cs[ny][nx] == ".":
                que.append([ny, nx])
                cs[ny][nx] = "#"
                dist[ny][nx] = dist[y][x] + 1
    t_ans = 0
    for a in dist:
        t_ans = max(t_ans, max(a))
    return t_ans


ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            cs = deepcopy(s)
            dist = dfs(cs, i, j)
            ans = max(ans, dist)
print(ans)

+from sys import stdin + +nii = lambda: list(map(int, stdin.readline().split())) +lnii = lambda: list(map(int, stdin.readline().split())) +from copy import deepcopy -import copy + +h, w = nii() +s = [list(eval(input())) for i in range(h)] -def BFS(h, w, sy, sx, xy_list): -    dist = [[-1] * w for i in range(h)] -    dist[sy][sx] = 0 -    xy_list[sy][sx] = "#" -    dq = deque() -    dq.append((sy, sx)) -    while dq: -        y, x = dq.popleft() +def dfs(cs, i, j): +    que = deque() +    que.append([i, j]) +    cs[i][j] = "#" +    dist = [[-1 for a in range(w)] for b in range(h)] +    dist[i][j] = 0 +    while que: +        y, x = que.popleft() -            if 0 <= ny < h and 0 <= nx < w and xy_list[ny][nx] != "#": -                dq.append((ny, nx)) -                xy_list[ny][nx] = "#" +            if 0 <= ny < h and 0 <= nx < w and cs[ny][nx] == ".": +                que.append([ny, nx]) +                cs[ny][nx] = "#" -    return dist +    t_ans = 0 +    for a in dist: +        t_ans = max(t_ans, max(a)) +    return t_ans -def main(): -    h, w = list(map(int, input().split())) -    s = [list(eval(input())) for i in range(h)] -    ans = 0 -    for hh in range(h): -        for ww in range(w): -            if s[hh][ww] == "#": -                continue -            xy_list = copy.deepcopy(s) -            dist = BFS(h, w, hh, ww, xy_list) -            for d in dist: -                ans = max(ans, max(d)) -    print(ans) - - -if __name__ == "__main__": -    main() +ans = 0 +for i in range(h): +    for j in range(w): +        if s[i][j] == ".": +            cs = deepcopy(s) +            dist = dfs(cs, i, j) +            ans = max(ans, dist) +print(ans)