def bfs_longest(x,y):

    queuex = [x]

    queuey = [y]

    queuedis = [0]

    looked = [[x,y]]

    ans = [0]

    while(len(queuex)):

        nowx = queuex.pop(0)

        nowy = queuey.pop(0)

        nowdis = queuedis.pop(0)

        search = [[nowx+1,nowy],[nowx-1,nowy],[nowx,nowy+1],[nowx,nowy-1]]

        for i in range(len(search)):

            if not (search[i] in looked):

                if maze[search[i][0]][search[i][1]] == ".":

                    queuex.append(search[i][0])

                    queuey.append(search[i][1])

                    queuedis.append(nowdis+1)

                    ans.append(nowdis+1)

                    looked.append([search[i][0],search[i][1]])

    return ans[-1]



h,w = list(map(int,input().split()))

maze = [["#" for _ in range(w+2)]for p in range(h+2)]

anchor = []

for i in range(h):

    data = str(eval(input()))

    for j in range(w):

        maze[i+1][j+1] = data[j]

        if data[j] == ".":

            anchor.append([i+1,j+1])



answer = 0

if (len(anchor)) == (h*w):

    print((h+w-2))

    exit()

for i in range(len(anchor)):

    answer = max(bfs_longest(anchor[i][0],anchor[i][1]),answer)

print(answer)
def bfs_longest(x,y):

    queuex = [x]

    queuey = [y]

    queuedis = [0]

    ans = [0]

    dis = [[-1 for _ in range(w+2)]for k in range(h+2)]

    dis[x][y] = 0

    while(len(queuex)):

        nowx = queuex.pop(0)

        nowy = queuey.pop(0)

        nowdis = queuedis.pop(0)

        search = [[nowx+1,nowy],[nowx-1,nowy],[nowx,nowy+1],[nowx,nowy-1]]

        for i in range(len(search)):

            if dis[search[i][0]][search[i][1]] == -1:

                if maze[search[i][0]][search[i][1]] == ".":

                    queuex.append(search[i][0])

                    queuey.append(search[i][1])

                    queuedis.append(nowdis+1)

                    ans.append(nowdis+1)

                    dis[search[i][0]][search[i][1]] = nowdis+1

    return ans[-1]



h,w = list(map(int,input().split()))

maze = [["#" for _ in range(w+2)]for p in range(h+2)]

anchor = []

for i in range(h):

    data = str(eval(input()))

    for j in range(w):

        maze[i+1][j+1] = data[j]

        if data[j] == ".":

            anchor.append([i+1,j+1])



answer = 0

for i in range(len(anchor)):

    answer = max(bfs_longest(anchor[i][0],anchor[i][1]),answer)

print(answer)
def bfs_longest(x, y):
    queuex = [x]
    queuey = [y]
    queuedis = [0]
    looked = [[x, y]]
    ans = [0]
    while len(queuex):
        nowx = queuex.pop(0)
        nowy = queuey.pop(0)
        nowdis = queuedis.pop(0)
        search = [
            [nowx + 1, nowy],
            [nowx - 1, nowy],
            [nowx, nowy + 1],
            [nowx, nowy - 1],
        ]
        for i in range(len(search)):
            if not (search[i] in looked):
                if maze[search[i][0]][search[i][1]] == ".":
                    queuex.append(search[i][0])
                    queuey.append(search[i][1])
                    queuedis.append(nowdis + 1)
                    ans.append(nowdis + 1)
                    looked.append([search[i][0], search[i][1]])
    return ans[-1]


h, w = list(map(int, input().split()))
maze = [["#" for _ in range(w + 2)] for p in range(h + 2)]
anchor = []
for i in range(h):
    data = str(eval(input()))
    for j in range(w):
        maze[i + 1][j + 1] = data[j]
        if data[j] == ".":
            anchor.append([i + 1, j + 1])
answer = 0
if (len(anchor)) == (h * w):
    print((h + w - 2))
    exit()
for i in range(len(anchor)):
    answer = max(bfs_longest(anchor[i][0], anchor[i][1]), answer)
print(answer)

def bfs_longest(x, y):
    queuex = [x]
    queuey = [y]
    queuedis = [0]
    ans = [0]
    dis = [[-1 for _ in range(w + 2)] for k in range(h + 2)]
    dis[x][y] = 0
    while len(queuex):
        nowx = queuex.pop(0)
        nowy = queuey.pop(0)
        nowdis = queuedis.pop(0)
        search = [
            [nowx + 1, nowy],
            [nowx - 1, nowy],
            [nowx, nowy + 1],
            [nowx, nowy - 1],
        ]
        for i in range(len(search)):
            if dis[search[i][0]][search[i][1]] == -1:
                if maze[search[i][0]][search[i][1]] == ".":
                    queuex.append(search[i][0])
                    queuey.append(search[i][1])
                    queuedis.append(nowdis + 1)
                    ans.append(nowdis + 1)
                    dis[search[i][0]][search[i][1]] = nowdis + 1
    return ans[-1]


h, w = list(map(int, input().split()))
maze = [["#" for _ in range(w + 2)] for p in range(h + 2)]
anchor = []
for i in range(h):
    data = str(eval(input()))
    for j in range(w):
        maze[i + 1][j + 1] = data[j]
        if data[j] == ".":
            anchor.append([i + 1, j + 1])
answer = 0
for i in range(len(anchor)):
    answer = max(bfs_longest(anchor[i][0], anchor[i][1]), answer)
print(answer)

-    looked = [[x, y]] +    dis = [[-1 for _ in range(w + 2)] for k in range(h + 2)] +    dis[x][y] = 0 -            if not (search[i] in looked): +            if dis[search[i][0]][search[i][1]] == -1: -                    looked.append([search[i][0], search[i][1]]) +                    dis[search[i][0]][search[i][1]] = nowdis + 1 -if (len(anchor)) == (h * w): -    print((h + w - 2)) -    exit()