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
    now = dc(raw)
    now[a][b] = 1
    ans = 0
    while True:
      last = dc(now)
      ans += 1
      check = 1
      for i in range(h):
        for j in range(w):
          if last[i][j] == 0:
            for x in nex:
              if 0 <= i+x[0] < h and 0 <= j+x[1] < w:
                if last[i+x[0]][j+x[1]] == 1:
                  now[i][j] = 1
                  break
            else:
              check = 0
      if check == 1:
        can.append(ans)
        break
print(max(can))