# -*- coding: utf-8 -*-

import sys

from collections import deque

from collections import defaultdict

 

H,W=list(map(int, sys.stdin.readline().split()))

S=[ sys.stdin.readline().strip() for _ in range(H) ]

 

D=[(1,0),(-1,0),(0,1),(0,-1)]

 

def bfs(start):

    Visit={}

    q=deque()

    q.append(start)

    Visit[start]=1

    L=defaultdict(lambda: float("inf"))    #距離

    L[start]=0

 

    while q:

        fro_x,fro_y=q.popleft()

        for dx,dy in D:

            to_x=fro_x+dx

            to_y=fro_y+dy

            if 0<=to_x<H and 0<=to_y<W:

                if S[to_x][to_y]=="." and (to_x,to_y) not in Visit:

                    Visit[to_x,to_y]=1

                    L[(to_x,to_y)]=min(L[(to_x,to_y)],L[(fro_x,fro_y)]+1)

                    q.append((to_x,to_y))

    if len(list(L.values()))==0:

        return 0

    else:

        return max(L.values())

 

ans=0

for h in range(H):

    for w in range(W):

        if S[h][w]==".":

            ans=max(ans,bfs((h,w)))

 

print(ans)
# -*- coding: utf-8 -*-

import sys

from collections import deque

from collections import defaultdict



H,W=list(map(int, sys.stdin.readline().split()))

S=[ sys.stdin.readline().strip() for _ in range(H) ]



D=[(1,0),(-1,0),(0,1),(0,-1)]



def bfs(start):

    Visit={}

    q=deque()

    q.append(start)

    Visit[start]=1

    L=defaultdict(lambda: 0)    #距離



    while q:

        fro_x,fro_y=q.popleft()

        for dx,dy in D:

            to_x=fro_x+dx

            to_y=fro_y+dy

            if 0<=to_x<H and 0<=to_y<W:

                if S[to_x][to_y]=="." and (to_x,to_y) not in Visit:

                    Visit[to_x,to_y]=1

                    L[(to_x,to_y)]=L[(fro_x,fro_y)]+1

                    q.append((to_x,to_y))



    return max(L.values())



ans=0

for h in range(H):

    for w in range(W):

        if S[h][w]==".":

            ans=max(ans,bfs((h,w)))



print(ans)

# -*- coding: utf-8 -*-
import sys
from collections import deque
from collections import defaultdict

H, W = list(map(int, sys.stdin.readline().split()))
S = [sys.stdin.readline().strip() for _ in range(H)]
D = [(1, 0), (-1, 0), (0, 1), (0, -1)]


def bfs(start):
    Visit = {}
    q = deque()
    q.append(start)
    Visit[start] = 1
    L = defaultdict(lambda: float("inf"))  # 距離
    L[start] = 0
    while q:
        fro_x, fro_y = q.popleft()
        for dx, dy in D:
            to_x = fro_x + dx
            to_y = fro_y + dy
            if 0 <= to_x < H and 0 <= to_y < W:
                if S[to_x][to_y] == "." and (to_x, to_y) not in Visit:
                    Visit[to_x, to_y] = 1
                    L[(to_x, to_y)] = min(L[(to_x, to_y)], L[(fro_x, fro_y)] + 1)
                    q.append((to_x, to_y))
    if len(list(L.values())) == 0:
        return 0
    else:
        return max(L.values())


ans = 0
for h in range(H):
    for w in range(W):
        if S[h][w] == ".":
            ans = max(ans, bfs((h, w)))
print(ans)

# -*- coding: utf-8 -*-
import sys
from collections import deque
from collections import defaultdict

H, W = list(map(int, sys.stdin.readline().split()))
S = [sys.stdin.readline().strip() for _ in range(H)]
D = [(1, 0), (-1, 0), (0, 1), (0, -1)]


def bfs(start):
    Visit = {}
    q = deque()
    q.append(start)
    Visit[start] = 1
    L = defaultdict(lambda: 0)  # 距離
    while q:
        fro_x, fro_y = q.popleft()
        for dx, dy in D:
            to_x = fro_x + dx
            to_y = fro_y + dy
            if 0 <= to_x < H and 0 <= to_y < W:
                if S[to_x][to_y] == "." and (to_x, to_y) not in Visit:
                    Visit[to_x, to_y] = 1
                    L[(to_x, to_y)] = L[(fro_x, fro_y)] + 1
                    q.append((to_x, to_y))
    return max(L.values())


ans = 0
for h in range(H):
    for w in range(W):
        if S[h][w] == ".":
            ans = max(ans, bfs((h, w)))
print(ans)

-    L = defaultdict(lambda: float("inf"))  # 距離 -    L[start] = 0 +    L = defaultdict(lambda: 0)  # 距離 -                    L[(to_x, to_y)] = min(L[(to_x, to_y)], L[(fro_x, fro_y)] + 1) +                    L[(to_x, to_y)] = L[(fro_x, fro_y)] + 1 -    if len(list(L.values())) == 0: -        return 0 -    else: -        return max(L.values()) +    return max(L.values())