H,W=list(map(int,input().split()))

S=[]

for _ in range(H):

    S.append(list(eval(input())))



from collections import deque



que=deque()

maxx=0



for i in range(H):

    for j in range(W):

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

            continue

        ans=[[500]*W for _ in range(H)]

        ans[i][j]=0

        que.append((i,j))

        while que:

            h,w=que.popleft()

            if h!=0 and S[h-1][w]==".":

                if ans[h-1][w]==500:

                    ans[h-1][w]=ans[h][w]+1

                    que.append((h-1,w))

            if h!=H-1 and S[h+1][w]==".":

                if ans[h+1][w]==500:

                    ans[h+1][w]=ans[h][w]+1

                    que.append((h+1,w))

            if w!=0 and S[h][w-1]==".":

                if ans[h][w-1]==500:

                    ans[h][w-1]=ans[h][w]+1

                    que.append((h,w-1))

            if w!=W-1 and S[h][w+1]==".":

                if ans[h][w+1]==500:

                    ans[h][w+1]=ans[h][w]+1

                    que.append((h,w+1))

            maxx=max(maxx,ans[h][w])

print(maxx)  

H,W=list(map(int,input().split()))

S=[]

for _ in range(H):

    S.append(list(eval(input())))



from collections import deque



que=deque()

maxx=0



for i in range(H):

    for j in range(W):

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

            continue

        ans=[[-1]*W for _ in range(H)]

        ans[i][j]=0

        que.append((i,j))

        while que:

            h,w=que.popleft()

            if h!=0 and S[h-1][w]==".":

                if ans[h-1][w]==-1:

                    ans[h-1][w]=ans[h][w]+1

                    que.append((h-1,w))

            if h!=H-1 and S[h+1][w]==".":

                if ans[h+1][w]==-1:

                    ans[h+1][w]=ans[h][w]+1

                    que.append((h+1,w))

            if w!=0 and S[h][w-1]==".":

                if ans[h][w-1]==-1:

                    ans[h][w-1]=ans[h][w]+1

                    que.append((h,w-1))

            if w!=W-1 and S[h][w+1]==".":

                if ans[h][w+1]==-1:

                    ans[h][w+1]=ans[h][w]+1

                    que.append((h,w+1))

            maxx=max(maxx,ans[h][w])

print(maxx)  

H, W = list(map(int, input().split()))
S = []
for _ in range(H):
    S.append(list(eval(input())))
from collections import deque

que = deque()
maxx = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            continue
        ans = [[500] * W for _ in range(H)]
        ans[i][j] = 0
        que.append((i, j))
        while que:
            h, w = que.popleft()
            if h != 0 and S[h - 1][w] == ".":
                if ans[h - 1][w] == 500:
                    ans[h - 1][w] = ans[h][w] + 1
                    que.append((h - 1, w))
            if h != H - 1 and S[h + 1][w] == ".":
                if ans[h + 1][w] == 500:
                    ans[h + 1][w] = ans[h][w] + 1
                    que.append((h + 1, w))
            if w != 0 and S[h][w - 1] == ".":
                if ans[h][w - 1] == 500:
                    ans[h][w - 1] = ans[h][w] + 1
                    que.append((h, w - 1))
            if w != W - 1 and S[h][w + 1] == ".":
                if ans[h][w + 1] == 500:
                    ans[h][w + 1] = ans[h][w] + 1
                    que.append((h, w + 1))
            maxx = max(maxx, ans[h][w])
print(maxx)

H, W = list(map(int, input().split()))
S = []
for _ in range(H):
    S.append(list(eval(input())))
from collections import deque

que = deque()
maxx = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            continue
        ans = [[-1] * W for _ in range(H)]
        ans[i][j] = 0
        que.append((i, j))
        while que:
            h, w = que.popleft()
            if h != 0 and S[h - 1][w] == ".":
                if ans[h - 1][w] == -1:
                    ans[h - 1][w] = ans[h][w] + 1
                    que.append((h - 1, w))
            if h != H - 1 and S[h + 1][w] == ".":
                if ans[h + 1][w] == -1:
                    ans[h + 1][w] = ans[h][w] + 1
                    que.append((h + 1, w))
            if w != 0 and S[h][w - 1] == ".":
                if ans[h][w - 1] == -1:
                    ans[h][w - 1] = ans[h][w] + 1
                    que.append((h, w - 1))
            if w != W - 1 and S[h][w + 1] == ".":
                if ans[h][w + 1] == -1:
                    ans[h][w + 1] = ans[h][w] + 1
                    que.append((h, w + 1))
            maxx = max(maxx, ans[h][w])
print(maxx)

-        ans = [[500] * W for _ in range(H)] +        ans = [[-1] * W for _ in range(H)] -                if ans[h - 1][w] == 500: +                if ans[h - 1][w] == -1: -                if ans[h + 1][w] == 500: +                if ans[h + 1][w] == -1: -                if ans[h][w - 1] == 500: +                if ans[h][w - 1] == -1: -                if ans[h][w + 1] == 500: +                if ans[h][w + 1] == -1: