import numpy as np

from collections import deque



h, w = list(map(int, input().split()))

s = [list(eval(input())) for _ in range(h)]



ans = 0

for i in range(h):

    for j in range(w):

        if s[i][j] == '#': continue

        q = deque()

        q.append([i, j, 0])

        visited = np.zeros((h + 5, w + 5), dtype = bool)

        visited[i][j] = True

        dirr = [[1, 0], [0, 1], [-1, 0], [0, -1]]

        mx = 0

        while len(q) != 0:

            x, y, z = q[0]

            for p in range(4):

                nx, ny = x + dirr[p][0], y + dirr[p][1]

                if 0 <= nx < h and 0 <= ny < w:

                    if not visited[nx][ny] and s[nx][ny] == '.':

                        q.append([nx, ny, z + 1])

                        visited[nx][ny] = True

                        ans = max(ans, z + 1)

            q.popleft()

print(ans)

from collections import deque

 

h, w = list(map(int, input().split()))

s = [list(eval(input())) for _ in range(h)]

 

dirr = ((1, 0), (0, 1), (-1, 0), (0, -1))

ans = 0

for i in range(h):

    for j in range(w):

        if s[i][j] == '#': continue

        q = deque()

        q.append((i, j, 0))

        visited = [[False] * w for _ in range(h)]

        visited[i][j] = True

        while q:

            x, y, z = q.popleft()

            for dx, dy in dirr:

                nx, ny = x + dx, y + dy

                if 0 <= nx < h and 0 <= ny < w:

                    if not visited[nx][ny] and s[nx][ny] == '.':

                        q.append((nx, ny, z + 1))

                        if z + 1 > ans: ans = z + 1

                        visited[nx][ny] = True

print(ans)

import numpy as np
from collections import deque

h, w = list(map(int, input().split()))
s = [list(eval(input())) for _ in range(h)]
ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            continue
        q = deque()
        q.append([i, j, 0])
        visited = np.zeros((h + 5, w + 5), dtype=bool)
        visited[i][j] = True
        dirr = [[1, 0], [0, 1], [-1, 0], [0, -1]]
        mx = 0
        while len(q) != 0:
            x, y, z = q[0]
            for p in range(4):
                nx, ny = x + dirr[p][0], y + dirr[p][1]
                if 0 <= nx < h and 0 <= ny < w:
                    if not visited[nx][ny] and s[nx][ny] == ".":
                        q.append([nx, ny, z + 1])
                        visited[nx][ny] = True
                        ans = max(ans, z + 1)
            q.popleft()
print(ans)

from collections import deque

h, w = list(map(int, input().split()))
s = [list(eval(input())) for _ in range(h)]
dirr = ((1, 0), (0, 1), (-1, 0), (0, -1))
ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            continue
        q = deque()
        q.append((i, j, 0))
        visited = [[False] * w for _ in range(h)]
        visited[i][j] = True
        while q:
            x, y, z = q.popleft()
            for dx, dy in dirr:
                nx, ny = x + dx, y + dy
                if 0 <= nx < h and 0 <= ny < w:
                    if not visited[nx][ny] and s[nx][ny] == ".":
                        q.append((nx, ny, z + 1))
                        if z + 1 > ans:
                            ans = z + 1
                        visited[nx][ny] = True
print(ans)

-import numpy as np +dirr = ((1, 0), (0, 1), (-1, 0), (0, -1)) -        q.append([i, j, 0]) -        visited = np.zeros((h + 5, w + 5), dtype=bool) +        q.append((i, j, 0)) +        visited = [[False] * w for _ in range(h)] -        dirr = [[1, 0], [0, 1], [-1, 0], [0, -1]] -        mx = 0 -        while len(q) != 0: -            x, y, z = q[0] -            for p in range(4): -                nx, ny = x + dirr[p][0], y + dirr[p][1] +        while q: +            x, y, z = q.popleft() +            for dx, dy in dirr: +                nx, ny = x + dx, y + dy -                        q.append([nx, ny, z + 1]) +                        q.append((nx, ny, z + 1)) +                        if z + 1 > ans: +                            ans = z + 1 -                        ans = max(ans, z + 1) -            q.popleft()