def dfs(i,x,y,maze):
    if not(0<=x<h) or not(0<=y<w):
        return
    if maze[x][y]=='#':
        return
    if maze[x][y]=='.':
        maze[x][y]=i
    if maze[x][y]>=i:
        maze[x][y]=i
        dfs(i+1,x+1,y,maze)
        dfs(i+1,x,y+1,maze)
        dfs(i+1,x-1,y,maze)
        dfs(i+1,x,y-1,maze)

import copy
h,w = map(int,input().split())
maze = []
for i in range(h):
    s = str(input())
    tmp = []
    for moji in s:
        tmp.append(moji)
    maze.append(tmp)

ans_list = []
for i in range(h):
    for j in range(w):
        myMaze = copy.copy(maze)
        dfs(0,i,j,myMaze)
        
        ans = 0
        for i in range(h):
            ans = max(ans,max([s for s in myMaze[i] if s!='#']))
        ans_list.append(ans)
print(max(ans_list))    
