R,C = map(int,input().split())
graph = [[i for i in input()] for j in range(R)]
visited = [[False for i in range(C)] for j in range(R)]

def dfs(start_y,start_x,goal_y,goal_x):
  queue = [[start_y,start_x,0]]
  while queue:
    now = queue.pop(0)
    visited[now[0]][now[1]] = True
    if now[0]==goal_y and now[1]==goal_x: return now[2]
    for next in [[1,0],[-1,0],[0,1],[0,-1]]:
      if now[0]+next[0] < 0 or now[1]+next[1] < 0: continue
      if now[0]+next[0] > R-1 or now[1]+next[1] > C-1: continue
      if visited[now[0]+next[0]][now[1]+next[1]]: continue
      if graph[now[0]+next[0]][now[1]+next[1]]=='#': continue
      queue.append([now[0]+next[0],now[1]+next[1],now[2]+1])
      visited[now[0]+next[0]][now[1]+next[1]] = True

ans = 0
for row_s in range(R):
  for column_s in range(C):
    for row_g in range(R):
      for column_g in range(C):
        if graph[row_s][column_s]=='#' or graph[row_g][column_g]=='#': continue
        visited = [[False for i in range(C)] for j in range(R)]
        ans = max(ans,dfs(row_s,column_s,row_g,column_g))
    
print(ans)