from collections import deque
import numpy as np
h, w = map(int,input().split())
s = [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.pop()
                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))