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

inf=10**3

d=((-1,0),(1,0),(0,-1),(0,1))

S=[["#"]*(w+2)]

S.extend([["#"]+[s for s in eval(input())]+["#"] for _ in range(h)])

S.append(["#"]*(w+2))

import heapq



def dist(a,b):

  D=[[inf]*(w+2) for _ in range(h+2)]

  D[a][b]=0

  Visit=[100*a+b]

  heapq.heapify(Visit)

  while Visit:

    v=heapq.heappop(Visit)

    vd,va,vb=v//(10**4),(v%(10**4))//100,v%100

    for dx,dy in d:

      if S[va+dx][vb+dy]=="." and D[va+dx][vb+dy]==inf:

        heapq.heappush(Visit,(vd+1)*(10**4)+(va+dx)*(10**2)+vb+dy)

        D[va+dx][vb+dy]=vd+1

  ret=0

  for i in range(h):

    for j in range(w):

      if D[i+1][j+1]<inf:

        ret=max(ret,D[i+1][j+1])

  return ret

ans=0

for i in range(h):

  for j in range(w):

    if S[i+1][j+1]==".":

      ans=max(dist(i+1,j+1),ans)

print(ans)







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

inf=10**3

d=((-1,0),(1,0),(0,-1),(0,1))

S=[["#"]*(w+2)]

S.extend([["#"]+[s for s in eval(input())]+["#"] for _ in range(h)])

S.append(["#"]*(w+2))

import collections

def dist(a,b):

  D=[[inf]*(w+2) for _ in range(h+2)]

  D[a][b]=0

  Visit=collections.deque()

  Visit.append(100*a+b)

  while Visit:

    v=Visit.popleft()

    va,vb=v//100,v%100

    for dx,dy in d:

      if S[va+dx][vb+dy]=="." and D[va+dx][vb+dy]==inf:

        Visit.append((va+dx)*100+(vb+dy))

        D[va+dx][vb+dy]=D[va][vb]+1

  ret=0

  for i in range(h):

    for j in range(w):

      if D[i+1][j+1]<inf:

        ret=max(ret,D[i+1][j+1])

  return ret

ans=0

for i in range(h):

  for j in range(w):

    if S[i+1][j+1]==".":

      ans=max(dist(i+1,j+1),ans)

print(ans)







h, w = list(map(int, input().split()))
inf = 10**3
d = ((-1, 0), (1, 0), (0, -1), (0, 1))
S = [["#"] * (w + 2)]
S.extend([["#"] + [s for s in eval(input())] + ["#"] for _ in range(h)])
S.append(["#"] * (w + 2))
import heapq


def dist(a, b):
    D = [[inf] * (w + 2) for _ in range(h + 2)]
    D[a][b] = 0
    Visit = [100 * a + b]
    heapq.heapify(Visit)
    while Visit:
        v = heapq.heappop(Visit)
        vd, va, vb = v // (10**4), (v % (10**4)) // 100, v % 100
        for dx, dy in d:
            if S[va + dx][vb + dy] == "." and D[va + dx][vb + dy] == inf:
                heapq.heappush(
                    Visit, (vd + 1) * (10**4) + (va + dx) * (10**2) + vb + dy
                )
                D[va + dx][vb + dy] = vd + 1
    ret = 0
    for i in range(h):
        for j in range(w):
            if D[i + 1][j + 1] < inf:
                ret = max(ret, D[i + 1][j + 1])
    return ret


ans = 0
for i in range(h):
    for j in range(w):
        if S[i + 1][j + 1] == ".":
            ans = max(dist(i + 1, j + 1), ans)
print(ans)

h, w = list(map(int, input().split()))
inf = 10**3
d = ((-1, 0), (1, 0), (0, -1), (0, 1))
S = [["#"] * (w + 2)]
S.extend([["#"] + [s for s in eval(input())] + ["#"] for _ in range(h)])
S.append(["#"] * (w + 2))
import collections


def dist(a, b):
    D = [[inf] * (w + 2) for _ in range(h + 2)]
    D[a][b] = 0
    Visit = collections.deque()
    Visit.append(100 * a + b)
    while Visit:
        v = Visit.popleft()
        va, vb = v // 100, v % 100
        for dx, dy in d:
            if S[va + dx][vb + dy] == "." and D[va + dx][vb + dy] == inf:
                Visit.append((va + dx) * 100 + (vb + dy))
                D[va + dx][vb + dy] = D[va][vb] + 1
    ret = 0
    for i in range(h):
        for j in range(w):
            if D[i + 1][j + 1] < inf:
                ret = max(ret, D[i + 1][j + 1])
    return ret


ans = 0
for i in range(h):
    for j in range(w):
        if S[i + 1][j + 1] == ".":
            ans = max(dist(i + 1, j + 1), ans)
print(ans)

-import heapq +import collections -    Visit = [100 * a + b] -    heapq.heapify(Visit) +    Visit = collections.deque() +    Visit.append(100 * a + b) -        v = heapq.heappop(Visit) -        vd, va, vb = v // (10**4), (v % (10**4)) // 100, v % 100 +        v = Visit.popleft() +        va, vb = v // 100, v % 100 -                heapq.heappush( -                    Visit, (vd + 1) * (10**4) + (va + dx) * (10**2) + vb + dy -                ) -                D[va + dx][vb + dy] = vd + 1 +                Visit.append((va + dx) * 100 + (vb + dy)) +                D[va + dx][vb + dy] = D[va][vb] + 1