H, W = map(int, input().split())
S = [list("#"+input()) for _ in range(H)] + [["#"]*(W+1)]
#print(S)
m = 0

for i in range(1, H+1):
    for j in range(1, W+1):
        if S[H-i][j] == "#":
            continue

        else:
            seen = [[False for _ in range(W+1)] for _ in range(H+1)]
            seen[H-i][j]=True
            #print(seen)

            D = [-1, 1]
            stack = [[H-i, j]]
            r = -1

            while stack:
                now = stack.pop()
                h = now[0]
                w = now[1]
                if h == 0 and w == W-1:
                    break
                #print(S[h][0][w])
                for d in D:
                    try:
                        if seen[h-d][w] ==True:
                            pass
                        elif S[h-d][w] == ".":
                            stack.append([h-d, w])
                            seen[h-d][w] = True
                    except:
                        pass
                    try:
                        if seen[h][w+d] ==True:
                            pass
                        elif S[h][w+d] == ".":
                            stack.append([h, w+d])
                            seen[h][w+d] = True
                    except:
                        pass
                #print(seen)
                r += 1
            m = max(m, r)
            #print(seen)
print(m)