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(list(map(str,eval(input()))))



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



def bfs(s):

    MAX = 0

    stack = deque([])

    stack.append(tuple(s))

    depth =dict()

    depth[tuple(s)] = 0

    goal = s

    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 k,d in list(depth.items()):

        if MAX < d:

            MAX = d

            goal = k



    return MAX, goal





for r in range(0,H):

    if "." in MAP[r]:

        start = [r, MAP[r].index(".")]



MAX, goal = bfs(tuple(start))

MAX, _ = bfs(tuple(goal))

print(MAX)

exit()

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(list(map(str, eval(input()))))
move = [[0, 1], [0, -1], [1, 0], [-1, 0]]


def bfs(s):
    MAX = 0
    stack = deque([])
    stack.append(tuple(s))
    depth = dict()
    depth[tuple(s)] = 0
    goal = s
    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 k, d in list(depth.items()):
        if MAX < d:
            MAX = d
            goal = k
    return MAX, goal


for r in range(0, H):
    if "." in MAP[r]:
        start = [r, MAP[r].index(".")]
MAX, goal = bfs(tuple(start))
MAX, _ = bfs(tuple(goal))
print(MAX)
exit()

-    MAP.append(tuple(map(str, eval(input())))) +    MAP.append(list(map(str, eval(input())))) -MAX = 0 -    global MAX +    MAX = 0 +    goal = s -    for d in list(depth.values()): -        MAX = max(MAX, d) +    for k, d in list(depth.items()): +        if MAX < d: +            MAX = d +            goal = k +    return MAX, goal -for i in range(0, H): -    for j in range(0, W): -        if MAP[i][j] == ".": -            bfs(tuple([i, j])) +for r in range(0, H): +    if "." in MAP[r]: +        start = [r, MAP[r].index(".")] +MAX, goal = bfs(tuple(start)) +MAX, _ = bfs(tuple(goal)) +exit()