from collections import deque



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

S=[eval(input()) for _ in range(h)]

inf=float("inf")

ans=0



for i in range(h):

    for j in range(w):

        if S[i][j]=="#":

            continue

        else:

            dist=[[inf for _ in range(w)] for _ in range(h)]

            dist[i][j]=0

            queue=deque([(i,j)])

            while queue:

                si,sj=queue.popleft()

                for ni,nj in [(si+1,sj),(si-1,sj),(si,sj+1),(si,sj-1)]:

                    if 0<=ni<=h-1 and 0<=nj<=w-1 and S[ni][nj] != "#":

                        if dist[ni][nj] > dist[si][sj] + 1:

                            dist[ni][nj] = dist[si][sj] + 1

                            queue.append((ni, nj))

                max_dist = 0

                for ii in range(h):

                    for jj in range(w):

                        if dist[ii][jj] != inf:

                            max_dist = max(max_dist, dist[ii][jj])

                            ans = max(max_dist,ans)

print(ans)

from collections import deque



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

S=[eval(input()) for _ in range(h)]

inf=float("inf")

ans=0



for i in range(h):

    for j in range(w):

        if S[i][j]=="#":

            continue

        else:

            dist=[[inf for _ in range(w)] for _ in range(h)]

            dist[i][j]=0

            que=deque([(i,j)])

            while que:

                si,sj=que.popleft()

                for ni,nj in [(si+1,sj),(si-1,sj),(si,sj+1),(si,sj-1)]:

                    if 0<=ni<=h-1 and 0<=nj<=w-1 and S[ni][nj]!="#":

                        if dist[ni][nj]>dist[si][sj]+1:

                            dist[ni][nj]=dist[si][sj]+1

                            ans=max(ans,dist[si][sj]+1)

                            que.append((ni,nj))



print(ans)
from collections import deque

h, w = list(map(int, input().split()))
S = [eval(input()) for _ in range(h)]
inf = float("inf")
ans = 0
for i in range(h):
    for j in range(w):
        if S[i][j] == "#":
            continue
        else:
            dist = [[inf for _ in range(w)] for _ in range(h)]
            dist[i][j] = 0
            queue = deque([(i, j)])
            while queue:
                si, sj = queue.popleft()
                for ni, nj in [(si + 1, sj), (si - 1, sj), (si, sj + 1), (si, sj - 1)]:
                    if 0 <= ni <= h - 1 and 0 <= nj <= w - 1 and S[ni][nj] != "#":
                        if dist[ni][nj] > dist[si][sj] + 1:
                            dist[ni][nj] = dist[si][sj] + 1
                            queue.append((ni, nj))
                max_dist = 0
                for ii in range(h):
                    for jj in range(w):
                        if dist[ii][jj] != inf:
                            max_dist = max(max_dist, dist[ii][jj])
                            ans = max(max_dist, ans)
print(ans)

from collections import deque

h, w = list(map(int, input().split()))
S = [eval(input()) for _ in range(h)]
inf = float("inf")
ans = 0
for i in range(h):
    for j in range(w):
        if S[i][j] == "#":
            continue
        else:
            dist = [[inf for _ in range(w)] for _ in range(h)]
            dist[i][j] = 0
            que = deque([(i, j)])
            while que:
                si, sj = que.popleft()
                for ni, nj in [(si + 1, sj), (si - 1, sj), (si, sj + 1), (si, sj - 1)]:
                    if 0 <= ni <= h - 1 and 0 <= nj <= w - 1 and S[ni][nj] != "#":
                        if dist[ni][nj] > dist[si][sj] + 1:
                            dist[ni][nj] = dist[si][sj] + 1
                            ans = max(ans, dist[si][sj] + 1)
                            que.append((ni, nj))
print(ans)

-            queue = deque([(i, j)]) -            while queue: -                si, sj = queue.popleft() +            que = deque([(i, j)]) +            while que: +                si, sj = que.popleft() -                            queue.append((ni, nj)) -                max_dist = 0 -                for ii in range(h): -                    for jj in range(w): -                        if dist[ii][jj] != inf: -                            max_dist = max(max_dist, dist[ii][jj]) -                            ans = max(max_dist, ans) +                            ans = max(ans, dist[si][sj] + 1) +                            que.append((ni, nj))