from collections import deque

def farthest(yi,xi):

    q = deque([])

    q.append((yi,xi))

    dis = [[-1]*(w+2) for i in range(h+2)]

    dis[yi][xi] = 0

    while q:

        y,x = q.popleft()

        for i in range(4):

            nexty = y + dy[i]

            nextx = x + dx[i]

            if maze[nexty][nextx] == '.' and dis[nexty][nextx] == -1:

                q.append((nexty,nextx))

                dis[nexty][nextx] = dis[y][x] + 1

    return dis[y][x]

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

maze = [['#'] * (w+2)]

maze += [['#']+[x for x in eval(input())]+['#'] for _ in range(h)]

maze += [['#'] * (w+2)]

dx = [-1,0,0,1]

dy = [0,1,-1,0]

maxdis = 1

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

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

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

                maxdis = max(maxdis,farthest(i,j))

print(maxdis)

from collections import deque

def max_dis_from(xi,yi):

    d = deque([(xi,yi)])

    dis = [[-1]*(w+2) for i in range(h+2)]

    dis[yi][xi] = 0

    while d:

        x,y = d.popleft()

        for i in range(4):

            newy = y+dy[i]

            newx = x+dx[i]

            if maze[newy][newx] == "." and dis[newy][newx] == -1:

                d.append((newx,newy))

                dis[newy][newx] = dis[y][x] + 1

    return dis[y][x]   

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

maze = []

maze.append(["#"]*(w+2))

for i in range(h):

    maze.append(["#"]+list(eval(input()))+["#"])

maze.append(["#"]*(w+2))

dx = [0,1,0,-1]

dy = [1,0,-1,0]

maxdis = 1

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

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

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

            maxdis = max(maxdis,max_dis_from(j,i))

print(maxdis)
from collections import deque


def farthest(yi, xi):
    q = deque([])
    q.append((yi, xi))
    dis = [[-1] * (w + 2) for i in range(h + 2)]
    dis[yi][xi] = 0
    while q:
        y, x = q.popleft()
        for i in range(4):
            nexty = y + dy[i]
            nextx = x + dx[i]
            if maze[nexty][nextx] == "." and dis[nexty][nextx] == -1:
                q.append((nexty, nextx))
                dis[nexty][nextx] = dis[y][x] + 1
    return dis[y][x]


h, w = list(map(int, input().split()))
maze = [["#"] * (w + 2)]
maze += [["#"] + [x for x in eval(input())] + ["#"] for _ in range(h)]
maze += [["#"] * (w + 2)]
dx = [-1, 0, 0, 1]
dy = [0, 1, -1, 0]
maxdis = 1
for i in range(1, h + 1):
    for j in range(1, w + 1):
        if maze[i][j] == ".":
            maxdis = max(maxdis, farthest(i, j))
print(maxdis)

from collections import deque


def max_dis_from(xi, yi):
    d = deque([(xi, yi)])
    dis = [[-1] * (w + 2) for i in range(h + 2)]
    dis[yi][xi] = 0
    while d:
        x, y = d.popleft()
        for i in range(4):
            newy = y + dy[i]
            newx = x + dx[i]
            if maze[newy][newx] == "." and dis[newy][newx] == -1:
                d.append((newx, newy))
                dis[newy][newx] = dis[y][x] + 1
    return dis[y][x]


h, w = list(map(int, input().split()))
maze = []
maze.append(["#"] * (w + 2))
for i in range(h):
    maze.append(["#"] + list(eval(input())) + ["#"])
maze.append(["#"] * (w + 2))
dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]
maxdis = 1
for i in range(1, h + 1):
    for j in range(1, w + 1):
        if maze[i][j] == ".":
            maxdis = max(maxdis, max_dis_from(j, i))
print(maxdis)

-def farthest(yi, xi): -    q = deque([]) -    q.append((yi, xi)) +def max_dis_from(xi, yi): +    d = deque([(xi, yi)]) -    while q: -        y, x = q.popleft() +    while d: +        x, y = d.popleft() -            nexty = y + dy[i] -            nextx = x + dx[i] -            if maze[nexty][nextx] == "." and dis[nexty][nextx] == -1: -                q.append((nexty, nextx)) -                dis[nexty][nextx] = dis[y][x] + 1 +            newy = y + dy[i] +            newx = x + dx[i] +            if maze[newy][newx] == "." and dis[newy][newx] == -1: +                d.append((newx, newy)) +                dis[newy][newx] = dis[y][x] + 1 -maze = [["#"] * (w + 2)] -maze += [["#"] + [x for x in eval(input())] + ["#"] for _ in range(h)] -maze += [["#"] * (w + 2)] -dx = [-1, 0, 0, 1] -dy = [0, 1, -1, 0] +maze = [] +maze.append(["#"] * (w + 2)) +for i in range(h): +    maze.append(["#"] + list(eval(input())) + ["#"]) +maze.append(["#"] * (w + 2)) +dx = [0, 1, 0, -1] +dy = [1, 0, -1, 0] -            maxdis = max(maxdis, farthest(i, j)) +            maxdis = max(maxdis, max_dis_from(j, i))