from collections import defaultdict,deque

H, W = list(map(int,input().split()))

MAP = []

for _ in range(H):

    MAP.append(tuple(map(str,eval(input()))))



move = [[0,1],[0,-1],[1,0],[-1,0]]

MAX = 0 



def bfs(s):

    global MAX

    stack = deque([])

    stack.append(tuple(s))

    depth =dict()

    depth[tuple(s)] = 0

    while stack:

        v = stack.popleft()

        for m in move:

            a = tuple([v[0]+m[0], v[1] + m[1]])

            if a[0] < H and a[0] >=  0 and a[1] < W and a[1] >= 0:

                if MAP[a[0]][a[1]] == '.' and not a in depth:

                    stack.append(a)

                    depth[a] = depth[v] + 1



    for d in list(depth.values()):

        MAX = max(MAX,d)





for i in range(0,H):

    for j in range(0,W):

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

            bfs(tuple([i,j]))



for i in range(0,W):

    for j in range(0,H):

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

            bfs(tuple([j,i]))



print(MAX)
from collections import defaultdict,deque

H, W = list(map(int,input().split()))

MAP = []

for _ in range(H):

    MAP.append(tuple(map(str,eval(input()))))



move = [[0,1],[0,-1],[1,0],[-1,0]]

MAX = 0 



def bfs(s):

    global MAX

    stack = deque([])

    stack.append(tuple(s))

    depth =dict()

    depth[tuple(s)] = 0

    while stack:

        v = stack.popleft()

        for m in move:

            a = tuple([v[0]+m[0], v[1] + m[1]])

            if a[0] < H and a[0] >=  0 and a[1] < W and a[1] >= 0:

                if MAP[a[0]][a[1]] == '.' and not a in depth:

                    stack.append(a)

                    depth[a] = depth[v] + 1



    for d in list(depth.values()):

        MAX = max(MAX,d)





for i in range(0,H):

    for j in range(0,W):

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

            bfs(tuple([i,j]))

print(MAX)
from collections import defaultdict, deque

H, W = list(map(int, input().split()))
MAP = []
for _ in range(H):
    MAP.append(tuple(map(str, eval(input()))))
move = [[0, 1], [0, -1], [1, 0], [-1, 0]]
MAX = 0


def bfs(s):
    global MAX
    stack = deque([])
    stack.append(tuple(s))
    depth = dict()
    depth[tuple(s)] = 0
    while stack:
        v = stack.popleft()
        for m in move:
            a = tuple([v[0] + m[0], v[1] + m[1]])
            if a[0] < H and a[0] >= 0 and a[1] < W and a[1] >= 0:
                if MAP[a[0]][a[1]] == "." and not a in depth:
                    stack.append(a)
                    depth[a] = depth[v] + 1
    for d in list(depth.values()):
        MAX = max(MAX, d)


for i in range(0, H):
    for j in range(0, W):
        if MAP[i][j] == ".":
            bfs(tuple([i, j]))
for i in range(0, W):
    for j in range(0, H):
        if MAP[j][i] == ".":
            bfs(tuple([j, i]))
print(MAX)

from collections import defaultdict, deque

H, W = list(map(int, input().split()))
MAP = []
for _ in range(H):
    MAP.append(tuple(map(str, eval(input()))))
move = [[0, 1], [0, -1], [1, 0], [-1, 0]]
MAX = 0


def bfs(s):
    global MAX
    stack = deque([])
    stack.append(tuple(s))
    depth = dict()
    depth[tuple(s)] = 0
    while stack:
        v = stack.popleft()
        for m in move:
            a = tuple([v[0] + m[0], v[1] + m[1]])
            if a[0] < H and a[0] >= 0 and a[1] < W and a[1] >= 0:
                if MAP[a[0]][a[1]] == "." and not a in depth:
                    stack.append(a)
                    depth[a] = depth[v] + 1
    for d in list(depth.values()):
        MAX = max(MAX, d)


for i in range(0, H):
    for j in range(0, W):
        if MAP[i][j] == ".":
            bfs(tuple([i, j]))
print(MAX)

-for i in range(0, W): -    for j in range(0, H): -        if MAP[j][i] == ".": -            bfs(tuple([j, i]))