from collections import deque
import copy
a,b=map(int,input().split())
maze=[list(input()) for i in range(a)]
ans=0
for i in range(a):
  for j in range(b):
    l=copy.deepcopy(maze)
    l[i][j]=0
    q=deque([[i,j]])
    while q:
      h,w=q.popleft()
      if 0<=h-1<a and 0<=w<b:
        if l[h-1][w]==".":
          l[h-1][w]=l[h][w]+1
          q.append([h-1,w])
      if 0<=h+1<a and 0<=w<b:
        if l[h+1][w]==".":
          l[h+1][w]=l[h][w]+1
          q.append([h+1,w])
      if 0<=h<a and 0<=w-1<b:
        if l[h][w-1]==".":
          l[h][w-1]=l[h][w]+1
          q.append([h,w-1])
      if 0<=h<a and 0<=w+1<b:
        if l[h][w+1]==".":
          l[h][w+1]=l[h][w]+1
          q.append([h,w+1])
    s=0
    for x in l:
      for y in x:
        if type(y)==int:
          if y>s:
            s=y
    if ans<s:
      ans=s
print(ans)