import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
inf = -9999999999
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    h, w = nm()
    s = s = [['#'] * (w+1)]
    for _ in range(h):
        temp = ['#']
        temp.extend(list(ns()))
        temp.extend(['#'])
        s.append(temp)
    s.append(['#'] * (w+1))
        
    def bfs(arr, x, y):
        que = deque([[x, y]])
        cost = 0
        dist = [[0]*(w+2) for _ in range(h+2)]
        for i in range(h+2):
            for j in range(w+2):
                if i == 0 or i == h + 1 or j == 0 or j == w + 1:
                    dist[i][j] = inf
        visited = set((x, y))
        while True:
            #print(x, y, que)
            now = que.popleft()
            if arr[now[0]][now[1]] == '.':
                if (now[0]+1, now[1]) not in visited:
                    que.append([now[0]+1, now[1]])
                    visited.add((now[0]+1, now[1]))
                    dist[now[0]+1][now[1]] = cost
                if (now[0], now[1]+1) not in visited:
                    que.append([now[0], now[1]+1])
                    visited.add((now[0], now[1]+1))
                    dist[now[0]][now[1]+1] = cost
                if (now[0]-1, now[1]) not in visited:
                    que.append([now[0]-1, now[1]])
                    visited.add((now[0]-1, now[1]))
                    dist[now[0]-1][now[1]] = cost
                if (now[0], now[1]-1) not in visited:
                    que.append([now[0], now[1]-1])
                    visited.add((now[0], now[1]-1))
                    dist[now[0]][now[1]-1] = cost
                cost += 1
            elif arr[now[0]][now[1]] == '#':
                dist[now[0]][now[1]] = inf
            if que == deque():
                break 
        mx = []
        for i in range(h+2):
            mx.append(max(dist[i]))       
        return max(mx)

    ans = []
    for i in range(1, h+1):
        for j in range(1, w+1):
            ans.append(bfs(s, i, j))

    print(max(ans))


if __name__ == '__main__':
    main()