from collections import deque

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

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



def bfs():

    global goal

    #0はstartとまだ通ってない場所

    d=[[float('inf')]*w for _ in range(h)]

    d[st[0]][st[1]]=0

    #進行方向

    x=[0,1,0,-1]

    y=[1,0,-1,0]



    p=deque([])

    p.append(st)#start座標を入れる



    while p:

        zahyo=p.popleft()

        for i in range(4):

            nx=zahyo[0]+x[i]

            ny=zahyo[1]+y[i]



            if 0<=nx<=h-1 and 0<=ny<=w-1 and d[nx][ny]==float('inf') and maze[nx][ny]=='.':

                d[nx][ny]=d[zahyo[0]][zahyo[1]]+1

                p.append([nx,ny])

                if goal<d[nx][ny]:

                    goal=d[nx][ny]



goal=0

ans=0

#starを決める

for i in range(h):

    for j in range(w):

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

            st=[i,j]

            bfs()

            if ans<goal:

                ans=goal

print(ans)

#BFS

from collections import deque

def bfs(i,j):

    q=deque()

    q.append((i,j))

    log=[[-1]*w for i in range(h)]

    log[i][j]=0

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

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

    long=0

    while q:

        #qの先頭を取り出す

        p=q.popleft()

        for i in range(4):

            nx=p[0]+dx[i]

            ny=p[1]+dy[i]



            if not(0<=nx<h and 0<=ny<w):continue

            if maze[nx][ny]=='#':continue

            if log[nx][ny]!=-1:continue

            log[nx][ny]=log[p[0]][p[1]]+1

            q.append((nx,ny))

            if int<=log[nx][ny]:long=log[nx][ny]

    return int



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

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



ans=0

for i in range(h):

    for j in range(w):

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

            temp=bfs(i,j)

            if ans<temp:ans=temp

print(ans)
from collections import deque

h, w = list(map(int, input().split()))
maze = [eval(input()) for i in range(h)]


def bfs():
    global goal
    # 0はstartとまだ通ってない場所
    d = [[float("inf")] * w for _ in range(h)]
    d[st[0]][st[1]] = 0
    # 進行方向
    x = [0, 1, 0, -1]
    y = [1, 0, -1, 0]
    p = deque([])
    p.append(st)  # start座標を入れる
    while p:
        zahyo = p.popleft()
        for i in range(4):
            nx = zahyo[0] + x[i]
            ny = zahyo[1] + y[i]
            if (
                0 <= nx <= h - 1
                and 0 <= ny <= w - 1
                and d[nx][ny] == float("inf")
                and maze[nx][ny] == "."
            ):
                d[nx][ny] = d[zahyo[0]][zahyo[1]] + 1
                p.append([nx, ny])
                if goal < d[nx][ny]:
                    goal = d[nx][ny]


goal = 0
ans = 0
# starを決める
for i in range(h):
    for j in range(w):
        if maze[i][j] == ".":
            st = [i, j]
            bfs()
            if ans < goal:
                ans = goal
print(ans)

# BFS
from collections import deque


def bfs(i, j):
    q = deque()
    q.append((i, j))
    log = [[-1] * w for i in range(h)]
    log[i][j] = 0
    dx = [0, 1, 0, -1]
    dy = [1, 0, -1, 0]
    long = 0
    while q:
        # qの先頭を取り出す
        p = q.popleft()
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if not (0 <= nx < h and 0 <= ny < w):
                continue
            if maze[nx][ny] == "#":
                continue
            if log[nx][ny] != -1:
                continue
            log[nx][ny] = log[p[0]][p[1]] + 1
            q.append((nx, ny))
            if int <= log[nx][ny]:
                long = log[nx][ny]
    return int


h, w = list(map(int, input().split()))
maze = [list(eval(input())) for i in range(h)]
ans = 0
for i in range(h):
    for j in range(w):
        if maze[i][j] == ".":
            temp = bfs(i, j)
            if ans < temp:
                ans = temp
print(ans)

+# BFS -h, w = list(map(int, input().split())) -maze = [eval(input()) for i in range(h)] + +def bfs(i, j): +    q = deque() +    q.append((i, j)) +    log = [[-1] * w for i in range(h)] +    log[i][j] = 0 +    dx = [0, 1, 0, -1] +    dy = [1, 0, -1, 0] +    long = 0 +    while q: +        # qの先頭を取り出す +        p = q.popleft() +        for i in range(4): +            nx = p[0] + dx[i] +            ny = p[1] + dy[i] +            if not (0 <= nx < h and 0 <= ny < w): +                continue +            if maze[nx][ny] == "#": +                continue +            if log[nx][ny] != -1: +                continue +            log[nx][ny] = log[p[0]][p[1]] + 1 +            q.append((nx, ny)) +            if int <= log[nx][ny]: +                long = log[nx][ny] +    return int -def bfs(): -    global goal -    # 0はstartとまだ通ってない場所 -    d = [[float("inf")] * w for _ in range(h)] -    d[st[0]][st[1]] = 0 -    # 進行方向 -    x = [0, 1, 0, -1] -    y = [1, 0, -1, 0] -    p = deque([]) -    p.append(st)  # start座標を入れる -    while p: -        zahyo = p.popleft() -        for i in range(4): -            nx = zahyo[0] + x[i] -            ny = zahyo[1] + y[i] -            if ( -                0 <= nx <= h - 1 -                and 0 <= ny <= w - 1 -                and d[nx][ny] == float("inf") -                and maze[nx][ny] == "." -            ): -                d[nx][ny] = d[zahyo[0]][zahyo[1]] + 1 -                p.append([nx, ny]) -                if goal < d[nx][ny]: -                    goal = d[nx][ny] - - -goal = 0 +h, w = list(map(int, input().split())) +maze = [list(eval(input())) for i in range(h)] -# starを決める -            st = [i, j] -            bfs() -            if ans < goal: -                ans = goal +            temp = bfs(i, j) +            if ans < temp: +                ans = temp