# -*- coding: utf-8 -*-

from collections import deque

############### TESTCASE ###############
test = ""
#test = \
"""
3 3
...
...
...
ans 4
"""

"""
3 5
...#.
.#.#.
.#...
ans 10
"""

"""
7 7
#######
#.#...#
#...#.#
#...#.#
#.#.#.#
#...#.#
#######
ans 12
"""

########################################
test = list(reversed(test.strip().splitlines()))
if test:
    def input2():
        return test.pop()
else:
    def input2():
        return input()
################# MAIN ################# 

h, w = map(int, input2().split())
s = ["#" * (w+2)]
s += ["#" + input2() + "#" for _ in range(h)]
s += ["#" * (w+2)]
t = [[0 for _ in range(w+2)] for _ in range(h+2)]

for hi in range(1, h+1):
    for wi in range(1, w+1):
        if s[hi][wi] == ".":
            history = {(hi, wi): 0}
            Q = deque([(hi, wi)])
            
            while Q:
                tmp = Q.popleft()
                next_to = (
                    (tmp[0] + 1, tmp[1]),
                    (tmp[0] - 1, tmp[1]),
                    (tmp[0], tmp[1] + 1),
                    (tmp[0], tmp[1] - 1))
                
                for nex in next_to:
                    form = s[nex[0]][nex[1]]
                    if (form == ".") and (nex not in history):
                        history[nex] = history[tmp] + 1
                        Q.append(nex)
                        
            t[hi][wi] = max(history.values())
        
print(max(max(t)))
#for _ in s:
#    print(_)
#for _ in t:
#    print(_)