from collections import deque

h,w = map(int, input().split())
grid = []
for i in range(h):
    s = list(input().rstrip())
    grid.append(s)
dxdy = [[0, 1], [1,0], [-1, 0], [0, -1]]
def max1(a,b):
    if a[0]>b[0]:
        return a
    else:
        return b
maxdist = 0
for i in range(h):
    for j in range(w):
        if grid[i][j]==".":
            dist = [[0]*w for _ in range(h)]
            visited = [[0]*w for _ in range(h)]
            que=deque()
            que.append([j,i])
            while que:
                v=que.popleft()
                x = v[0]
                y = v[1]
                visited[y][x]=1

                for k in dxdy:
                    dx = k[0]
                    dy = k[1]
                    if((x+dx<w and y+dy<h) and ((x+dx)>-1)and(y+dy)>-1) and not visited[y+dy][x+dx]:
                        maxdist = max(dist[y+dy][x+dx], maxdist)
                        dist[y+dy][x+dx]=dist[y][x]+1
                        que.append([x+dx, y+dy])
print(maxdist)
