from collections import deque
if __name__ == "__main__":
    h, w = map(int, input().split())
    s = []

    for _ in range(h):
        h_i = input()
        s.append(h_i)

    
    ans = (-1)*float('inf')
    
    
    for s_r in range(h):
        for s_c in range(w):
            visited = []
            for _ in range(h):
                w_i = [False] * w
                visited.append(w_i)
            d = deque()
            d.appendleft((s_r, s_c, 0))
            part = 0
            while d:
                now = d.pop()
                visited[now[0]][now[1]] = True
                part = max(now[2], part)
                if now[0] + 1 < h and s[now[0] + 1][now[1]] != "#" and not visited[now[0] + 1][now[1]]:
                    d.appendleft((now[0] + 1, now[1], now[2] + 1))
                if now[0] - 1 >= 0 and s[now[0] - 1][now[1]] != "#" and not visited[now[0] - 1][now[1]]:
                    d.appendleft((now[0] - 1, now[1], now[2] + 1))
                if now[1] + 1 < w and s[now[0]][now[1] + 1] != "#" and not visited[now[0]][now[1] + 1]:
                    d.appendleft((now[0], now[1]+1, now[2] + 1))
                if now[1] - 1 >= 0 and s[now[0]][now[1] - 1] != "#" and not visited[now[0]][now[1] - 1]:
                    d.appendleft((now[0], now[1] - 1, now[2] + 1))
            if ans < part:
                ans = part
    print(ans)