h,w = map(int,input().split())
raw = []
for _ in range(h):
  tmp = input()
  add = []
  for j in range(w):
    if tmp[j] == '.':
      add.append(0)
    else:
      add.append(2)
  raw.append(add)
nex = [[0,1],[0,-1],[1,0],[-1,0]]
can = []
from copy import deepcopy as dc
for a in range(h):
  for b in range(w):
    if raw[a][b] == 2:
      continue
    last = dc(raw)
    last[a][b] = 1
    ans = 0
    while True:
      now = dc(last)
      ans += 1
      for i in range(h):
        for j in range(w):
          if last[i][j] == 1:
            for x in nex:
              if 0 <= i+x[0] < h and 0 <= j+x[1] < w:
                if now[i+x[0]][j+x[1]] == 0:
                  now[i+x[0]][j+x[1]] = 1
      check = 1
      for i in range(h):
        for j in range(w):
          check *= now[i][j]
      if check > 0:
        can.append(ans)
        #print(a,b)
        #for y in now:
          #print(y)
        break
      #if (a,b) == (0,4):
        #print(ans)
        #for y in now:
          #print(y)
      last = dc(now)
print(max(can))
#print(can)
#print(raw)