import copy

def maze_maker():
    h,w = map(int,input().split())
    maze = []
    for i in range(h):
        maze.append(list(input()))
    return maze,h,w

def search():
    v = 0
    now = [[i1,j1,0]]
    go = True
    while go:
        for i in now[:]:
            #上
            if i[0] == 0:
                pass
            else:
                if meiro[i[0]-1][i[1]] == ".":
                    now.append([i[0]-1,i[1],i[2]+1])
                    meiro[i[0]-1][i[1]] = i[2]+1
            #下
            if i[0] == h-1:
                pass
            else:
                if meiro[i[0]+1][i[1]] == ".":
                    now.append([i[0]+1,i[1],i[2]+1])
                    meiro[i[0]+1][i[1]] = i[2]+1
            #左
            if i[1] == 0:
                pass
            else:
                if meiro[i[0]][i[1]-1] == ".":
                    now.append([i[0],i[1]-1,i[2]+1])
                    meiro[i[0]][i[1]-1] = i[2]+1
            #右
            if i[1] == w-1:
                pass
            else:
                if meiro[i[0]][i[1]+1] == ".":
                    now.append([i[0],i[1]+1,i[2]+1])
                    meiro[i[0]][i[1]+1] = i[2]+1
            v = max(v,i[2])
            now.remove(i)
            if now == []:
                return v


saitankeiro = 0
maze,h,w = maze_maker()
for i1 in range(h):
    for j1 in range(w):
        if maze[i1][j1] != "#":
            meiro = copy.deepcopy(maze)
            saitankeiro = max(saitankeiro,search())
print(saitankeiro)