from collections import deque

h, w = map(int, input().split())
s = [str(input()) for i in range(h)]
ans = 0
for sy in range(h):
    for sx in range(w):
        for gy in range(h):
            for gx in range(w):
                reached = [[False for i in range(w)] for j in range(h)]
                dist = 0
                d = deque([])
                d.append([sx, sy, dist])
                while(d):
                    x, y, dist = d.popleft()
                    if s[y][x] == '#':
                        continue
                    if reached[y][x]:
                        continue
                    if x == gx and y == gy:
                        break 
                    reached[y][x] = True
                    dist += 1
                    if x+1 < w and not reached[y][x+1]:
                        d.append([x+1, y, dist])
                    if x-1 >= 0 and not reached[y][x-1]:
                        d.append([x-1, y, dist])
                    if y+1 < h and not reached[y+1][x]:
                        d.append([x, y+1, dist])
                    if y-1 >= 0 and not reached[y-1][x]: 
                        d.append([x, y-1, dist])
                ans = max(ans, dist)


print(ans)
