from collections import deque



def bfs(sy,sx):

    dist[sy][sx]=0

    q=deque([[sy,sx]])

    while q:

        cy,cx=q.popleft()

        for i,j in ([1,0],[-1,0],[0,1],[0,-1]):

            ny,nx=cy+i,cx+j

            if ny<0 or h-1<ny or nx<0 or w-1<nx or path[ny][nx]=='#':continue

            if path[ny][nx]=='.' and dist[ny][nx]==-1:

                dist[ny][nx]=dist[cy][cx]+1

                q.append([ny,nx])

    max_dist=-1

    for i in range(h):

        for j in range(w):

            if path[i][j]=='#':continue

            max_dist=max(max_dist,dist[i][j])

    return max_dist



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

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

ans=0

for i in range(h):

    for j in range(w):

        if path[i][j]=='#':

            continue

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

        t=bfs(i,j)

        ans=max(ans,t)

print(ans)
from collections import deque

def bfs(sy,sx):

  q=deque([[sy,sx]])

  visited[sy][sx]=0

  while q:

    y,x=q.popleft()

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

      ny,nx=y+dy,x+dx

      if ny<0 or ny>h-1 or nx<0 or nx>w-1 or path[ny][nx]=="#":continue

      if path[ny][nx]=="." and visited[ny][nx]==-1:

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

        q.append([ny,nx])

  res=-1

  for i in range(h):

    for j in range(w):

      res=max(visited[i][j],res)

  return res



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

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

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

sy,sx=0,0

gy,gx=0,0

ans=0

for i in range(h):

  for j in range(w):

    if path[i][j]=="#":continue

    sy=i

    sx=j

    visited=[[-1]*w for _ in range(h)]

    t=bfs(sy,sx)

    ans=max(t,ans)

print(ans)



from collections import deque


def bfs(sy, sx):
    dist[sy][sx] = 0
    q = deque([[sy, sx]])
    while q:
        cy, cx = q.popleft()
        for i, j in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            ny, nx = cy + i, cx + j
            if ny < 0 or h - 1 < ny or nx < 0 or w - 1 < nx or path[ny][nx] == "#":
                continue
            if path[ny][nx] == "." and dist[ny][nx] == -1:
                dist[ny][nx] = dist[cy][cx] + 1
                q.append([ny, nx])
    max_dist = -1
    for i in range(h):
        for j in range(w):
            if path[i][j] == "#":
                continue
            max_dist = max(max_dist, dist[i][j])
    return max_dist


h, w = list(map(int, input().split()))
path = [eval(input()) for i in range(h)]
ans = 0
for i in range(h):
    for j in range(w):
        if path[i][j] == "#":
            continue
        dist = [[-1] * w for i in range(h)]
        t = bfs(i, j)
        ans = max(ans, t)
print(ans)

from collections import deque


def bfs(sy, sx):
    q = deque([[sy, sx]])
    visited[sy][sx] = 0
    while q:
        y, x = q.popleft()
        for dy, dx in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            ny, nx = y + dy, x + dx
            if ny < 0 or ny > h - 1 or nx < 0 or nx > w - 1 or path[ny][nx] == "#":
                continue
            if path[ny][nx] == "." and visited[ny][nx] == -1:
                visited[ny][nx] = visited[y][x] + 1
                q.append([ny, nx])
    res = -1
    for i in range(h):
        for j in range(w):
            res = max(visited[i][j], res)
    return res


h, w = list(map(int, input().split()))
path = [eval(input()) for i in range(h)]
visited = [[-1] * w for i in range(h)]
sy, sx = 0, 0
gy, gx = 0, 0
ans = 0
for i in range(h):
    for j in range(w):
        if path[i][j] == "#":
            continue
        sy = i
        sx = j
        visited = [[-1] * w for _ in range(h)]
        t = bfs(sy, sx)
        ans = max(t, ans)
print(ans)

-    dist[sy][sx] = 0 +    visited[sy][sx] = 0 -        cy, cx = q.popleft() -        for i, j in ([1, 0], [-1, 0], [0, 1], [0, -1]): -            ny, nx = cy + i, cx + j -            if ny < 0 or h - 1 < ny or nx < 0 or w - 1 < nx or path[ny][nx] == "#": +        y, x = q.popleft() +        for dy, dx in ([1, 0], [-1, 0], [0, 1], [0, -1]): +            ny, nx = y + dy, x + dx +            if ny < 0 or ny > h - 1 or nx < 0 or nx > w - 1 or path[ny][nx] == "#": -            if path[ny][nx] == "." and dist[ny][nx] == -1: -                dist[ny][nx] = dist[cy][cx] + 1 +            if path[ny][nx] == "." and visited[ny][nx] == -1: +                visited[ny][nx] = visited[y][x] + 1 -    max_dist = -1 +    res = -1 -            if path[i][j] == "#": -                continue -            max_dist = max(max_dist, dist[i][j]) -    return max_dist +            res = max(visited[i][j], res) +    return res +visited = [[-1] * w for i in range(h)] +sy, sx = 0, 0 +gy, gx = 0, 0 -        dist = [[-1] * w for i in range(h)] -        t = bfs(i, j) -        ans = max(ans, t) +        sy = i +        sx = j +        visited = [[-1] * w for _ in range(h)] +        t = bfs(sy, sx) +        ans = max(t, ans)