import sys

from collections import deque



sr = lambda: sys.stdin.readline().rstrip()

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))



H, W = lr()

grid = [sr() for _ in range(H)]



def bfs(sy, sx):

    d = [[float('inf')] * W for _ in range(H)]

    dy = [0, 1, 0, -1]

    dx = [1, 0, -1, 0]

    que = deque()

    que.append((sy, sx))

    d[sy][sx] = 0

    while que:

        p = que.popleft()

        for i in range(4):

            ny = p[0] + dy[i]

            nx = p[1] + dx[i]                

            if 0 <= ny < H and 0 <= nx < W and \

                    grid[ny][nx] != '#' and d[ny][nx] == float('inf'):

                d[ny][nx] = d[p[0]][p[1]] + 1

                que.append((ny, nx))

    max = 0

    for row in d:

        for r in row:

            if r != float('inf') and r > max:

                max = r

    return max



answer = 0    

for i in range(H):

    for j in range(W):

        if grid[i][j] == '#':

            continue

        result = bfs(i, j)

        if result > answer:

            answer = result



print(answer)

# 49

import sys

from collections import deque



sr = lambda: sys.stdin.readline().rstrip()

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))



def bfs(sy, sx):

    dist = [[-INF] * W for _ in range(H)]

    dist[sy][sx] = 0

    que = deque([(sy, sx)])

    popleft = que.popleft; append = que.append

    while que:

        y, x = popleft()

        cur = dist[y][x]

        for dy, dx in zip([0, 1, 0, -1], [1, 0, -1, 0]):            

            ny = y + dy

            nx = x + dx

            if 0 <= ny < H and 0 <= nx < W and \

                    grid[ny][nx] != '#' and dist[ny][nx] == -INF:

                dist[ny][nx] = cur + 1

                append((ny, nx))

    ret = max(max(x for x in di)for di in dist)

    return ret



INF = 10 ** 3

H, W = lr()

grid = [sr() for _ in range(H)]

answer = max(max(bfs(i, j) if grid[i][j] == '.' else 0 for j in range(W)) for i in range(H))

print(answer)

# 22

import sys
from collections import deque

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
H, W = lr()
grid = [sr() for _ in range(H)]


def bfs(sy, sx):
    d = [[float("inf")] * W for _ in range(H)]
    dy = [0, 1, 0, -1]
    dx = [1, 0, -1, 0]
    que = deque()
    que.append((sy, sx))
    d[sy][sx] = 0
    while que:
        p = que.popleft()
        for i in range(4):
            ny = p[0] + dy[i]
            nx = p[1] + dx[i]
            if (
                0 <= ny < H
                and 0 <= nx < W
                and grid[ny][nx] != "#"
                and d[ny][nx] == float("inf")
            ):
                d[ny][nx] = d[p[0]][p[1]] + 1
                que.append((ny, nx))
    max = 0
    for row in d:
        for r in row:
            if r != float("inf") and r > max:
                max = r
    return max


answer = 0
for i in range(H):
    for j in range(W):
        if grid[i][j] == "#":
            continue
        result = bfs(i, j)
        if result > answer:
            answer = result
print(answer)
# 49

import sys
from collections import deque

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))


def bfs(sy, sx):
    dist = [[-INF] * W for _ in range(H)]
    dist[sy][sx] = 0
    que = deque([(sy, sx)])
    popleft = que.popleft
    append = que.append
    while que:
        y, x = popleft()
        cur = dist[y][x]
        for dy, dx in zip([0, 1, 0, -1], [1, 0, -1, 0]):
            ny = y + dy
            nx = x + dx
            if (
                0 <= ny < H
                and 0 <= nx < W
                and grid[ny][nx] != "#"
                and dist[ny][nx] == -INF
            ):
                dist[ny][nx] = cur + 1
                append((ny, nx))
    ret = max(max(x for x in di) for di in dist)
    return ret


INF = 10**3
H, W = lr()
grid = [sr() for _ in range(H)]
answer = max(
    max(bfs(i, j) if grid[i][j] == "." else 0 for j in range(W)) for i in range(H)
)
print(answer)
# 22

-H, W = lr() -grid = [sr() for _ in range(H)] -    d = [[float("inf")] * W for _ in range(H)] -    dy = [0, 1, 0, -1] -    dx = [1, 0, -1, 0] -    que = deque() -    que.append((sy, sx)) -    d[sy][sx] = 0 +    dist = [[-INF] * W for _ in range(H)] +    dist[sy][sx] = 0 +    que = deque([(sy, sx)]) +    popleft = que.popleft +    append = que.append -        p = que.popleft() -        for i in range(4): -            ny = p[0] + dy[i] -            nx = p[1] + dx[i] +        y, x = popleft() +        cur = dist[y][x] +        for dy, dx in zip([0, 1, 0, -1], [1, 0, -1, 0]): +            ny = y + dy +            nx = x + dx -                and d[ny][nx] == float("inf") +                and dist[ny][nx] == -INF -                d[ny][nx] = d[p[0]][p[1]] + 1 -                que.append((ny, nx)) -    max = 0 -    for row in d: -        for r in row: -            if r != float("inf") and r > max: -                max = r -    return max +                dist[ny][nx] = cur + 1 +                append((ny, nx)) +    ret = max(max(x for x in di) for di in dist) +    return ret -answer = 0 -for i in range(H): -    for j in range(W): -        if grid[i][j] == "#": -            continue -        result = bfs(i, j) -        if result > answer: -            answer = result +INF = 10**3 +H, W = lr() +grid = [sr() for _ in range(H)] +answer = max( +    max(bfs(i, j) if grid[i][j] == "." else 0 for j in range(W)) for i in range(H) +) -# 49 +# 22