#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

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



    distance = 0

    d = [(1, 0), (0, 1), (-1, 0), (0, -1)]

    while q:

        #qの先頭を取り出す

        p=q.popleft()

        for x, y in d:

            nx = p[0] + x

            ny = p[1] + y

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

            if s[nx][ny] == "#":continue

            if log[nx][ny] >= 0:continue

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

            q.append((nx, ny))

            if distance < log[nx][ny]:distance = log[nx][ny]



    return distance



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

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

distance = 0



for i in range(h):

    for j in range(w):

        if s[i][j] == "#":continue

        temp = bfs(i, j)

        if temp >= distance:distance = temp

print(distance)

# 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
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
    distance = 0
    d = [(1, 0), (0, 1), (-1, 0), (0, -1)]
    while q:
        # qの先頭を取り出す
        p = q.popleft()
        for x, y in d:
            nx = p[0] + x
            ny = p[1] + y
            if not (0 <= nx < h and 0 <= ny < w):
                continue
            if s[nx][ny] == "#":
                continue
            if log[nx][ny] >= 0:
                continue
            log[nx][ny] = log[p[0]][p[1]] + 1
            q.append((nx, ny))
            if distance < log[nx][ny]:
                distance = log[nx][ny]
    return distance


h, w = list(map(int, input().split()))
s = [list(eval(input())) for i in range(h)]
distance = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            continue
        temp = bfs(i, j)
        if temp >= distance:
            distance = temp
print(distance)

-    dx = [0, 1, 0, -1] -    dy = [1, 0, -1, 0] -    long = 0 +    distance = 0 +    d = [(1, 0), (0, 1), (-1, 0), (0, -1)] -        for i in range(4): -            nx = p[0] + dx[i] -            ny = p[1] + dy[i] +        for x, y in d: +            nx = p[0] + x +            ny = p[1] + y -            if maze[nx][ny] == "#": +            if s[nx][ny] == "#": -            if log[nx][ny] != -1: +            if log[nx][ny] >= 0: -            if int <= log[nx][ny]: -                long = log[nx][ny] -    return int +            if distance < log[nx][ny]: +                distance = log[nx][ny] +    return distance -maze = [list(eval(input())) for i in range(h)] -ans = 0 +s = [list(eval(input())) for i in range(h)] +distance = 0 -        if maze[i][j] == ".": -            temp = bfs(i, j) -            if ans < temp: -                ans = temp -print(ans) +        if s[i][j] == "#": +            continue +        temp = bfs(i, j) +        if temp >= distance: +            distance = temp +print(distance)