### BUGGY CODE ###

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])
    ans = 0
    for i in range(h * w - 1):
        if ls2[i] == []:
            continue
        for j in range(i+1, h * w):
            if ls2[j] == []:
                continue
            else:
                ans = max(ans, route(i, j))
    print(ans)
if __name__ == '__main__':
    main()

### FIXED CODE ###

from collections import deque

def main():
    h, w = map(int, input().split())
    ls = [input() for _ in range(h)]

    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] == '#':
                continue
            if i >= 1 and ls[i-1][j] != '#':
                ls2[trans(i, j)].append(trans(i-1, j))
            if i <= h-2 and ls[i+1][j] != '#':
                ls2[trans(i, j)].append(trans(i + 1, j))
            if j <= w-2 and ls[i][j+1] != '#':
                ls2[trans(i, j)].append(trans(i, j + 1))
            if j >= 1 and ls[i][j-1] != '#':
                ls2[trans(i, j)].append(trans(i, j - 1))


    #print(ls2)


    def route(i):
        count = 1
        ss = deque(ls2[i])
        next = deque()
        explored = {i}
        while ss or next:
            if not ss:
                count +=1
                ss = next
                next = deque()
            now =ss.popleft()
            if now in explored:
                continue
            else:
                explored.add(now)
                next.extend(ls2[now])
        return count-1
    ans = 0
    for i in range(h * w - 1):
        if ls2[i] == []:
            continue
        ans = max(ans, route(i))

    print(ans)
if __name__ == '__main__':
    main()