h,w = map(int,input().split())
maze = [["#"]*(w+2)]+[["#"]+list(input())+["#"] for _ in range(h)]+[["#"]*(w+2)]
import copy

def f(i,j):
  arr = []
  if done[i][j+1] == 0 and maze[i][j+1] == ".":
    arr.append([i,j+1])
    done[i][j+1] = 1
  if done[i][j-1] == 0 and maze[i][j-1] == ".":
    arr.append([i,j-1])
    done[i][j-1] = 1
  if done[i+1][j] == 0 and maze[i+1][j] == ".":
    arr.append([i+1,j])
    done[i+1][j] = 1
  if done[i-1][j] == 0 and maze[i-1][j] == ".":
    arr.append([i-1,j])
    done[i-1][j] = 1
  return arr

ans = 0
#print(maze)
for i in range(1,h+1):
  for  j in range(1,w+1):
    if maze[i][j] == "#":
      continue
    done = [[1]*(w+2)]+[[1]+[0]*w +[1] for _ in range(h)]+[[1]*(w+2)]
    next_wait = [[i,j]]
    done[i][j] == 1
    cnt = 0
    while next_wait:
      wait = copy.copy(next_wait)
      next_wait = []
      #print(wait)
      while wait:
        now = wait.pop()
        next_wait += f(now[0],now[1])
      cnt += 1
    ans = max(ans,cnt)
print(max(0,ans-1))