from collections import deque

import copy



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

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



ans=0



for hh in range(h):

 for ww in range(w):

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

  c=copy.deepcopy(ss)

  xx=c[hh][ww]

  if xx=='#':

   continue

  dist[hh][ww]=0

  dq=deque()

  dq.append((hh,ww))

  c[hh][ww]='#'

  while dq:

   y,x=dq.popleft()

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

    nx=x+dx

    ny=y+dy

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

     dq.append((ny,nx))

     c[ny][nx]='#'

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

  for i in dist:

   ans=max(ans,max(i))

print(ans)
from collections import deque

import copy



def BFS(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



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(hh,ww,xy_list)

  for d in dist:

   ans=max(ans,max(d))



print(ans)
from collections import deque
import copy

h, w = list(map(int, input().split()))
ss = [list(eval(input())) for i in range(h)]
ans = 0
for hh in range(h):
    for ww in range(w):
        dist = [[-1] * (w + 1) for i in range(h + 1)]
        c = copy.deepcopy(ss)
        xx = c[hh][ww]
        if xx == "#":
            continue
        dist[hh][ww] = 0
        dq = deque()
        dq.append((hh, ww))
        c[hh][ww] = "#"
        while dq:
            y, x = dq.popleft()
            for dx, dy in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
                nx = x + dx
                ny = y + dy
                if 0 <= nx < w and 0 <= ny < h and c[ny][nx] != "#":
                    dq.append((ny, nx))
                    c[ny][nx] = "#"
                    dist[ny][nx] = dist[y][x] + 1
        for i in dist:
            ans = max(ans, max(i))
print(ans)

from collections import deque
import copy


def BFS(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


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(hh, ww, xy_list)
        for d in dist:
            ans = max(ans, max(d))
print(ans)

+ +def BFS(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 + + -ss = [list(eval(input())) for i in range(h)] +s = [list(eval(input())) for i in range(h)] -        dist = [[-1] * (w + 1) for i in range(h + 1)] -        c = copy.deepcopy(ss) -        xx = c[hh][ww] -        if xx == "#": +        if s[hh][ww] == "#": -        dist[hh][ww] = 0 -        dq = deque() -        dq.append((hh, ww)) -        c[hh][ww] = "#" -        while dq: -            y, x = dq.popleft() -            for dx, dy in [[1, 0], [-1, 0], [0, 1], [0, -1]]: -                nx = x + dx -                ny = y + dy -                if 0 <= nx < w and 0 <= ny < h and c[ny][nx] != "#": -                    dq.append((ny, nx)) -                    c[ny][nx] = "#" -                    dist[ny][nx] = dist[y][x] + 1 -        for i in dist: -            ans = max(ans, max(i)) +        xy_list = copy.deepcopy(s) +        dist = BFS(hh, ww, xy_list) +        for d in dist: +            ans = max(ans, max(d))