#python3
from collections import deque         
INF = int(1e9)
dd = [(-1, 0), (1, 0), (0, 1), (0, -1)]

def main():
    h, w = map(int, input().split())
    maze = [input() for _ in range(h)]
    ans = -1 
    
    for i in range(h):
        for j in range(w):
            if maze[i][j] == "#":
                continue
            g = [[INF for _ in range(w)] for _ in range(h)] 
            q = deque()
            q.append((i, j))
            g[i][j] = 0
            while len(q) > 0:
                pi, pj = q.popleft()
                for dx, dy in dd:
                    x = pi + dx
                    y = pj + dy
                    if (x < 0) | (y < 0) | (x >= h) | (y >= w): 
                        continue
                    if maze[x][y] == "#":
                        continue
                    if g[x][y] != INF:
                        continue
                    q.append((x, y))
                    g[x][y] = g[pi][pj]+1 
            

            for i in range(h):
                for j in range(w):
                    if g[i][j] == INF:
                        continue
                    ans = max(ans, g[i][j])
    print(ans)
main()