from collections import deque

INF = 114514191981036436433-4
h,w = map(int,input().split())

c = [[] for _ in range(h)]
for i in range(h):
    c[i] = input()
            
dx = [1,0,-1,0]
dy = [0,1,0,-1]

ans = 0
for i in range(h):
    for j in range(w):
        for l in range(h):
            for m in range(w):
                if c[i][j] == "#" or c[l][m] == "#":
                    continue
                if i == l and j == m:
                    continue
                    
                d = [[INF for i in range(w)] for j in range(h)]
                
                sx,sy = j,i
                gx,gy = m,l
                
                d[sy][sx] = 0
                que = deque([[sy,sx]])

                while que:
                    y,x = que.popleft()

                    for k in range(4):
                        nx = x + dx[k]
                        ny = y + dy[k]

                        if 0<=nx and nx<w and 0<=ny and ny<h and c[y][x] != '#':
                            if d[ny][nx] > d[y][x] + 1:
                                d[ny][nx]=d[y][x] + 1
                                que.append([ny,nx])
                                
                if d[gy][gx] != INF:         
                    ans = max(d[gy][gx],ans)

print(ans)