import collections

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

if H == W == 1:

    print((0))

    exit()

if (H == 1 and W == 2) or (H == 2 and W == 1):

    print((1))

    exit()

LL=[]

for i in range(H):

    LL.append(eval(input()))



L = ((1,0),(0,1),(-1,0),(0,-1))

q = collections.deque()

max_L = []

for i in range(H):

    for j in range(W):

        d = [[0]*W for i in range(H)]

        if LL[i][j] ==".":

            q.append((i,j))

            d[i][j] = 0

            max1 = 0

            while q:

                x,y = q.popleft()

                for dx,dy in L:

                    if 0>x+dx or x+dx>H-1 or 0>y+dy or y+dy>W-1 or d[x+dx][y+dy] !=0:

                        continue

                    if  LL[x+dx][y+dy] == ".":

                        d[x+dx][y+dy] = d[x][y] +1

                        q.append((x+dx,y+dy))

                        max1 = max(max1,d[x+dx][y+dy])

                        max_L.append(max1)

                        #print(q,d ,max1)

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

L = [[]*w for i in range(h)]



for i in range(h):

    L[i] = list("#" + eval(input()) + "#")

L = [["#" for i in range(w+2)]] + L + [["#" for i in range(w+2)]]

#print(L)



from collections import deque

ans = 0

q = deque([])

for j in range(1,h+1):

    for i in range(1,w+1):

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

        li = ((1,0),(0,1),(-1,0),(0,-1))

        #print(j,i)

        if L[j][i] == ".":

            cost[j][i] = 0

        cost_max = 0

        q.append((j,i))

        while q:

            #print(q)

            r,s = q.popleft()

            

            for dh,dw in li:

                nh,nw = r+dh,s+dw

                #print(L[nh][nw],)

                if L[nh][nw] =="." and cost[nh][nw] == -1 :

                    cost[nh][nw] = cost[r][s] + 1

                    #print(cost[nh][nw],cost[j][i])

                    #print(cost)

                    cost_max = max(cost_max,cost[nh][nw])

                    q.append((nh,nw))

        ans = max(ans,cost_max)

print(ans)
import collections

H, W = list(map(int, input().split()))
if H == W == 1:
    print((0))
    exit()
if (H == 1 and W == 2) or (H == 2 and W == 1):
    print((1))
    exit()
LL = []
for i in range(H):
    LL.append(eval(input()))
L = ((1, 0), (0, 1), (-1, 0), (0, -1))
q = collections.deque()
max_L = []
for i in range(H):
    for j in range(W):
        d = [[0] * W for i in range(H)]
        if LL[i][j] == ".":
            q.append((i, j))
            d[i][j] = 0
            max1 = 0
            while q:
                x, y = q.popleft()
                for dx, dy in L:
                    if (
                        0 > x + dx
                        or x + dx > H - 1
                        or 0 > y + dy
                        or y + dy > W - 1
                        or d[x + dx][y + dy] != 0
                    ):
                        continue
                    if LL[x + dx][y + dy] == ".":
                        d[x + dx][y + dy] = d[x][y] + 1
                        q.append((x + dx, y + dy))
                        max1 = max(max1, d[x + dx][y + dy])
                        max_L.append(max1)
                        # print(q,d ,max1)
print((max(max_L)))

h, w = list(map(int, input().split()))
L = [[] * w for i in range(h)]
for i in range(h):
    L[i] = list("#" + eval(input()) + "#")
L = [["#" for i in range(w + 2)]] + L + [["#" for i in range(w + 2)]]
# print(L)
from collections import deque

ans = 0
q = deque([])
for j in range(1, h + 1):
    for i in range(1, w + 1):
        cost = [[-1] * (w + 2) for i in range(h + 2)]
        li = ((1, 0), (0, 1), (-1, 0), (0, -1))
        # print(j,i)
        if L[j][i] == ".":
            cost[j][i] = 0
        cost_max = 0
        q.append((j, i))
        while q:
            # print(q)
            r, s = q.popleft()
            for dh, dw in li:
                nh, nw = r + dh, s + dw
                # print(L[nh][nw],)
                if L[nh][nw] == "." and cost[nh][nw] == -1:
                    cost[nh][nw] = cost[r][s] + 1
                    # print(cost[nh][nw],cost[j][i])
                    # print(cost)
                    cost_max = max(cost_max, cost[nh][nw])
                    q.append((nh, nw))
        ans = max(ans, cost_max)
print(ans)

-import collections +h, w = list(map(int, input().split())) +L = [[] * w for i in range(h)] +for i in range(h): +    L[i] = list("#" + eval(input()) + "#") +L = [["#" for i in range(w + 2)]] + L + [["#" for i in range(w + 2)]] +# print(L) +from collections import deque -H, W = list(map(int, input().split())) -if H == W == 1: -    print((0)) -    exit() -if (H == 1 and W == 2) or (H == 2 and W == 1): -    print((1)) -    exit() -LL = [] -for i in range(H): -    LL.append(eval(input())) -L = ((1, 0), (0, 1), (-1, 0), (0, -1)) -q = collections.deque() -max_L = [] -for i in range(H): -    for j in range(W): -        d = [[0] * W for i in range(H)] -        if LL[i][j] == ".": -            q.append((i, j)) -            d[i][j] = 0 -            max1 = 0 -            while q: -                x, y = q.popleft() -                for dx, dy in L: -                    if ( -                        0 > x + dx -                        or x + dx > H - 1 -                        or 0 > y + dy -                        or y + dy > W - 1 -                        or d[x + dx][y + dy] != 0 -                    ): -                        continue -                    if LL[x + dx][y + dy] == ".": -                        d[x + dx][y + dy] = d[x][y] + 1 -                        q.append((x + dx, y + dy)) -                        max1 = max(max1, d[x + dx][y + dy]) -                        max_L.append(max1) -                        # print(q,d ,max1) -print((max(max_L))) +ans = 0 +q = deque([]) +for j in range(1, h + 1): +    for i in range(1, w + 1): +        cost = [[-1] * (w + 2) for i in range(h + 2)] +        li = ((1, 0), (0, 1), (-1, 0), (0, -1)) +        # print(j,i) +        if L[j][i] == ".": +            cost[j][i] = 0 +        cost_max = 0 +        q.append((j, i)) +        while q: +            # print(q) +            r, s = q.popleft() +            for dh, dw in li: +                nh, nw = r + dh, s + dw +                # print(L[nh][nw],) +                if L[nh][nw] == "." and cost[nh][nw] == -1: +                    cost[nh][nw] = cost[r][s] + 1 +                    # print(cost[nh][nw],cost[j][i]) +                    # print(cost) +                    cost_max = max(cost_max, cost[nh][nw]) +                    q.append((nh, nw)) +        ans = max(ans, cost_max) +print(ans)