import numpy as np

from collections import deque

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

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

#meiro[y][x]

def bfs(a,b):#a縦b横

    maxdist=0

    da=[1,-1,0,0]

    db=[0,0,1,-1]

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

    dist[a][b]=0

    stack=deque([(a,b)])

    while stack:

        y,x=stack.popleft()

        D=dist[y][x]

        for dy,dx in zip(da,db):

            X=x+dx

            Y=y+dy

            if 0<=Y and Y<=h-1 and X<=w-1 and 0<=X:

                if meiro[Y][X]=='.':

                    if dist[Y][X]==-1:

                        dist[Y][X]=D+1

                        stack.append((Y,X))

                    elif dist[Y][X]>0:

                        dist[Y][X]=min(dist[Y][X],D+1)

                else:

                    dist[Y][X]==-(10**6)

    return dist

saidai=0

for i in range(h):

    for j in range(w):

        if meiro[i][j]=='.':

            saidai=max(saidai,np.array(bfs(i,j)).max())

print(saidai)
from collections import deque



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

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

# meiro[y][x]





def bfs(a, b):  # a縦b横

    mx_dist = 0

    dx = [1, 0, -1, 0]

    dy = [0, 1, 0, -1]

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

    dist[a][b] = 0

    que = deque([])

    que.append((a, b))

    while que:

        y, x = que.popleft()

        D = dist[y][x]

        for i in range(4):

            X = x + dx[i]

            Y = y + dy[i]

            if 0 <= Y and Y <= h - 1 and X <= w - 1 and 0 <= X:

                if meiro[Y][X] == ".":

                    if dist[Y][X] == -1:

                        dist[Y][X] = D + 1

                        que.append((Y, X))

                        mx_dist = max(mx_dist, D + 1)



    return mx_dist





saidai = 0

for i in range(h):

    for j in range(w):

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

            saidai = max(saidai, bfs(i, j))

print(saidai)

import numpy as np
from collections import deque

h, w = list(map(int, input().split()))
meiro = [list(eval(input())) for i in range(h)]
# meiro[y][x]
def bfs(a, b):  # a縦b横
    maxdist = 0
    da = [1, -1, 0, 0]
    db = [0, 0, 1, -1]
    dist = [[-1] * w for i in range(h)]
    dist[a][b] = 0
    stack = deque([(a, b)])
    while stack:
        y, x = stack.popleft()
        D = dist[y][x]
        for dy, dx in zip(da, db):
            X = x + dx
            Y = y + dy
            if 0 <= Y and Y <= h - 1 and X <= w - 1 and 0 <= X:
                if meiro[Y][X] == ".":
                    if dist[Y][X] == -1:
                        dist[Y][X] = D + 1
                        stack.append((Y, X))
                    elif dist[Y][X] > 0:
                        dist[Y][X] = min(dist[Y][X], D + 1)
                else:
                    dist[Y][X] == -(10**6)
    return dist


saidai = 0
for i in range(h):
    for j in range(w):
        if meiro[i][j] == ".":
            saidai = max(saidai, np.array(bfs(i, j)).max())
print(saidai)

from collections import deque

h, w = list(map(int, input().split()))
meiro = [list(eval(input())) for i in range(h)]
# meiro[y][x]
def bfs(a, b):  # a縦b横
    mx_dist = 0
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
    dist = [[-1] * w for i in range(h)]
    dist[a][b] = 0
    que = deque([])
    que.append((a, b))
    while que:
        y, x = que.popleft()
        D = dist[y][x]
        for i in range(4):
            X = x + dx[i]
            Y = y + dy[i]
            if 0 <= Y and Y <= h - 1 and X <= w - 1 and 0 <= X:
                if meiro[Y][X] == ".":
                    if dist[Y][X] == -1:
                        dist[Y][X] = D + 1
                        que.append((Y, X))
                        mx_dist = max(mx_dist, D + 1)
    return mx_dist


saidai = 0
for i in range(h):
    for j in range(w):
        if meiro[i][j] == ".":
            saidai = max(saidai, bfs(i, j))
print(saidai)

-import numpy as np -    maxdist = 0 -    da = [1, -1, 0, 0] -    db = [0, 0, 1, -1] +    mx_dist = 0 +    dx = [1, 0, -1, 0] +    dy = [0, 1, 0, -1] -    stack = deque([(a, b)]) -    while stack: -        y, x = stack.popleft() +    que = deque([]) +    que.append((a, b)) +    while que: +        y, x = que.popleft() -        for dy, dx in zip(da, db): -            X = x + dx -            Y = y + dy +        for i in range(4): +            X = x + dx[i] +            Y = y + dy[i] -                        stack.append((Y, X)) -                    elif dist[Y][X] > 0: -                        dist[Y][X] = min(dist[Y][X], D + 1) -                else: -                    dist[Y][X] == -(10**6) -    return dist +                        que.append((Y, X)) +                        mx_dist = max(mx_dist, D + 1) +    return mx_dist -            saidai = max(saidai, np.array(bfs(i, j)).max()) +            saidai = max(saidai, bfs(i, j))