from _collections import deque

def main():
    h, w = map(int, input().split())
    ls = []
    for _ in range(h):
        ls1 = []
        s = input()
        for i in range(w):
            if s[i] == '.':
                ls1.append(0)
            else:
                ls1.append(1)
        ls.append(ls1)

    def trans(a, b):
        return a * w + b

    ls2 = [[] for _ in range(h * w)]

    for i in range(h):
        for j in range(w):
            # check ij
            if ls[i][j] == 1:
                continue
            if 0 <= i < h and 0 <= j - 1 < w and ls[i][j - 1] == 0:
                ls2[trans(i, j)].append(trans(i, j - 1))
                #print(ls2)
            if 0 <= i + 1 < h and 0 <= j < w and ls[i + 1][j] == 0:
                ls2[trans(i, j)].append(trans(i + 1, j))
                #print(ls2)
            if 0 <= i - 1 < h and 0 <= j < w and ls[i - 1][j] == 0:
                ls2[trans(i, j)].append(trans(i - 1, j))
                #print(ls2)
            if 0 <= i < h and 0 <= j + 1 < w and ls[i][j + 1] == 0:
                ls2[trans(i, j)].append(trans(i, j + 1))

    def route(i, j):
        count = 1
        ss = deque(ls2[i])
        next = deque()
        explored = {i}
        while True:
            if not ss:
                count +=1
                ss = next
                next = deque()
            now =ss.popleft()
            if now in explored:
                continue
            if now == j:
                return count
            else:
                explored.add(now)
                next.extend(ls2[now])

    ls3 = [0] * (h * w)

    for i in range(h * w - 1):
        if ls2[i] == []:
            continue
        count = 0
        for j in range(i+1, h * w):
            if ls2[j] == []:
                continue
            else:
                count = max(count, route(i, j))
        ls3[i] = count
    print(max(ls3))
if __name__ == '__main__':
    main()