from collections import deque

def main():
    H, W = map(int, input().split())
    field = "#"*(W+2)
    field += "#" + "##".join([input() for _ in range(H)]) + "#"
    field += "#"*(W+2)

    INF = 10**9
    cost = [INF]*len(field)
    move = [-1, 1, -(W+2), W+2]
    def bfs(s):
        q = deque()

        cost[s] = 0
        q.append(s)

        while q:
            now = q.popleft()
            now_cost = cost[now]
            for dx in move:
                nv = now + dx

                if field[nv] == "#" or cost[nv] < INF:
                    continue
                else:
                    cost[nv] = now_cost + 1
                    q.append(nv)
    
    ans = 0
    for si in range(H):
        for sj in range(W):
            for gi in range(H):
                for gj in range(W):
                    start = (si+1)*(W+2)+sj+1
                    goal = (gi+1)*(W+2)+gj+1
                    if start == goal or "#" in [field[start], field[goal]]:
                        continue
                    cost = [INF] * len(field)
                    bfs(start)
                    ans = max(ans, cost[goal])
    print(ans)

if __name__ == "__main__":
    main()