def clear_maze(sx, sy, maze):



    INF=-10**9

    global cnt

    cnt=0

    distance = [[INF for i in range(w+1)] for j in range(h+1)]

    #    distance = [[None]*field_x_length]*field_y_length



    def bfs():

        global cnt

        queue = []



        queue.insert(0, (sx, sy))



        distance[sx][sy] = 0



        while len(queue):

            x, y = queue.pop()



            for i in range(0, 4):

                nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]





                if (0 <= nx and  0 <= ny  and maze[nx][ny] != '#' and distance[nx][ny] == INF):

                    queue.insert(0, (nx, ny))



                    distance[nx][ny] = distance[x][y] + 1

                    if cnt<distance[nx][ny]:

                        cnt=distance[nx][ny]

        return cnt

    return bfs()





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

maze=[list(eval(input())) for i in range(h)]

t=[[0]*w for i in range(h)]



for i in range(h):

    maze[i]=['#']+maze[i]+['#']

maze=[['#' for i in range(w+2)]]+maze+[['#' for i in range(w+2)]]



ans=0

for i in range(1, h + 1):

    for j in range(1, w + 1):

        if maze[i][j] == '#':

            continue

        v = (clear_maze(i, j, maze))



        if ans <= v:

            ans = v

print(ans)
import collections

from collections import deque



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

maze=[list(eval(input())) for i in range(h)]



# 枠を囲う

for i in range(h):

    maze[i]=['#']+maze[i]+['#']

maze=[['#' for i in range(w+2)]]+maze+[['#' for i in range(w+2)]]



def clear_maze(sx, sy):



    INF=-10**9

    distance = [[INF for i in range(w+2)] for j in range(h+2)]

    #    distance = [[None]*field_x_length]*field_y_length

    def bfs():

        d = deque()

        d.append((sx, sy))

        distance[sx][sy] = 0

        ans=0



        while len(d):

            x, y = d.popleft()



            for i in range(0, 4):

                nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]



                if (0 <= nx and  0 <= ny  and maze[nx][ny] != '#' and distance[nx][ny] == INF):

                    d.append((nx, ny))

                    distance[nx][ny] = distance[x][y] + 1

                    ans=max(distance[nx][ny],ans)





        return ans



    return bfs()



m=0

for i in range(1,h+1):

    for j in range(1,w+1):

        if maze[i][j] == '.':

            x=clear_maze(i,j)

            m=max(x,m)

print(m)
def clear_maze(sx, sy, maze):
    INF = -(10**9)
    global cnt
    cnt = 0
    distance = [[INF for i in range(w + 1)] for j in range(h + 1)]
    #    distance = [[None]*field_x_length]*field_y_length
    def bfs():
        global cnt
        queue = []
        queue.insert(0, (sx, sy))
        distance[sx][sy] = 0
        while len(queue):
            x, y = queue.pop()
            for i in range(0, 4):
                nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]
                if (
                    0 <= nx
                    and 0 <= ny
                    and maze[nx][ny] != "#"
                    and distance[nx][ny] == INF
                ):
                    queue.insert(0, (nx, ny))
                    distance[nx][ny] = distance[x][y] + 1
                    if cnt < distance[nx][ny]:
                        cnt = distance[nx][ny]
        return cnt

    return bfs()


h, w = list(map(int, input().split()))
maze = [list(eval(input())) for i in range(h)]
t = [[0] * w for i in range(h)]
for i in range(h):
    maze[i] = ["#"] + maze[i] + ["#"]
maze = [["#" for i in range(w + 2)]] + maze + [["#" for i in range(w + 2)]]
ans = 0
for i in range(1, h + 1):
    for j in range(1, w + 1):
        if maze[i][j] == "#":
            continue
        v = clear_maze(i, j, maze)
        if ans <= v:
            ans = v
print(ans)

import collections
from collections import deque

h, w = list(map(int, input().split()))
maze = [list(eval(input())) for i in range(h)]
# 枠を囲う
for i in range(h):
    maze[i] = ["#"] + maze[i] + ["#"]
maze = [["#" for i in range(w + 2)]] + maze + [["#" for i in range(w + 2)]]


def clear_maze(sx, sy):
    INF = -(10**9)
    distance = [[INF for i in range(w + 2)] for j in range(h + 2)]
    #    distance = [[None]*field_x_length]*field_y_length
    def bfs():
        d = deque()
        d.append((sx, sy))
        distance[sx][sy] = 0
        ans = 0
        while len(d):
            x, y = d.popleft()
            for i in range(0, 4):
                nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]
                if (
                    0 <= nx
                    and 0 <= ny
                    and maze[nx][ny] != "#"
                    and distance[nx][ny] == INF
                ):
                    d.append((nx, ny))
                    distance[nx][ny] = distance[x][y] + 1
                    ans = max(distance[nx][ny], ans)
        return ans

    return bfs()


m = 0
for i in range(1, h + 1):
    for j in range(1, w + 1):
        if maze[i][j] == ".":
            x = clear_maze(i, j)
            m = max(x, m)
print(m)

-def clear_maze(sx, sy, maze): +import collections +from collections import deque + +h, w = list(map(int, input().split())) +maze = [list(eval(input())) for i in range(h)] +# 枠を囲う +for i in range(h): +    maze[i] = ["#"] + maze[i] + ["#"] +maze = [["#" for i in range(w + 2)]] + maze + [["#" for i in range(w + 2)]] + + +def clear_maze(sx, sy): -    global cnt -    cnt = 0 -    distance = [[INF for i in range(w + 1)] for j in range(h + 1)] +    distance = [[INF for i in range(w + 2)] for j in range(h + 2)] -        global cnt -        queue = [] -        queue.insert(0, (sx, sy)) +        d = deque() +        d.append((sx, sy)) -        while len(queue): -            x, y = queue.pop() +        ans = 0 +        while len(d): +            x, y = d.popleft() -                    queue.insert(0, (nx, ny)) +                    d.append((nx, ny)) -                    if cnt < distance[nx][ny]: -                        cnt = distance[nx][ny] -        return cnt +                    ans = max(distance[nx][ny], ans) +        return ans -h, w = list(map(int, input().split())) -maze = [list(eval(input())) for i in range(h)] -t = [[0] * w for i in range(h)] -for i in range(h): -    maze[i] = ["#"] + maze[i] + ["#"] -maze = [["#" for i in range(w + 2)]] + maze + [["#" for i in range(w + 2)]] -ans = 0 +m = 0 -        if maze[i][j] == "#": -            continue -        v = clear_maze(i, j, maze) -        if ans <= v: -            ans = v -print(ans) +        if maze[i][j] == ".": +            x = clear_maze(i, j) +            m = max(x, m) +print(m)