from collections import deque

import numpy as np

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

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

result = []

for xx in range(h):

    for yy in range(w):

        if s[xx][yy]==".":

            visit = np.array([np.array([-1 for _ in range(w)]) for __ in range(h)])

            visit[xx][yy] = 0



            q = deque([[xx,yy]])

            while q:

                x, y = q.popleft()

                for i in [-1, 1]:

                    if 0 <= x+i and x+i < h:

                        if s[x+i][y] != "#" and visit[x+i][y] < 0:

                            visit[x+i][y] = visit[x][y]+1

                            q.append([x+i, y])

                    if 0 <= y+i and y+i < w:

                        if s[x][y+i] != "#" and visit[x][y+i] < 0:

                            visit[x][y+i] = visit[x][y]+1

                            q.append([x, y+i])

            result.append(max(visit.flatten()))

print((max(result)))
from collections import deque

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

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

result = []

for xx in range(h):

    for yy in range(w):

        if s[xx][yy]==".":

            visit = [[-1 for _ in range(w)] for __ in range(h)]

            visit[xx][yy] = 0



            q = deque([[xx,yy]])

            while q:

                x, y = q.popleft()

                for i in [-1, 1]:

                    if 0 <= x+i and x+i < h:

                        if s[x+i][y] != "#" and visit[x+i][y] < 0:

                            visit[x+i][y] = visit[x][y]+1

                            q.append([x+i, y])

                    if 0 <= y+i and y+i < w:

                        if s[x][y+i] != "#" and visit[x][y+i] < 0:

                            visit[x][y+i] = visit[x][y]+1

                            q.append([x, y+i])

            result.append(max([max(i) for i in visit]))

print((max(result)))
from collections import deque
import numpy as np

h, w = list(map(int, input().split()))
s = [eval(input()) for _ in range(h)]
result = []
for xx in range(h):
    for yy in range(w):
        if s[xx][yy] == ".":
            visit = np.array([np.array([-1 for _ in range(w)]) for __ in range(h)])
            visit[xx][yy] = 0
            q = deque([[xx, yy]])
            while q:
                x, y = q.popleft()
                for i in [-1, 1]:
                    if 0 <= x + i and x + i < h:
                        if s[x + i][y] != "#" and visit[x + i][y] < 0:
                            visit[x + i][y] = visit[x][y] + 1
                            q.append([x + i, y])
                    if 0 <= y + i and y + i < w:
                        if s[x][y + i] != "#" and visit[x][y + i] < 0:
                            visit[x][y + i] = visit[x][y] + 1
                            q.append([x, y + i])
            result.append(max(visit.flatten()))
print((max(result)))

from collections import deque

h, w = list(map(int, input().split()))
s = [eval(input()) for _ in range(h)]
result = []
for xx in range(h):
    for yy in range(w):
        if s[xx][yy] == ".":
            visit = [[-1 for _ in range(w)] for __ in range(h)]
            visit[xx][yy] = 0
            q = deque([[xx, yy]])
            while q:
                x, y = q.popleft()
                for i in [-1, 1]:
                    if 0 <= x + i and x + i < h:
                        if s[x + i][y] != "#" and visit[x + i][y] < 0:
                            visit[x + i][y] = visit[x][y] + 1
                            q.append([x + i, y])
                    if 0 <= y + i and y + i < w:
                        if s[x][y + i] != "#" and visit[x][y + i] < 0:
                            visit[x][y + i] = visit[x][y] + 1
                            q.append([x, y + i])
            result.append(max([max(i) for i in visit]))
print((max(result)))

-import numpy as np -            visit = np.array([np.array([-1 for _ in range(w)]) for __ in range(h)]) +            visit = [[-1 for _ in range(w)] for __ in range(h)] -            result.append(max(visit.flatten())) +            result.append(max([max(i) for i in visit]))