# -*- coding: utf-8 -*-



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

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

for i in maze:

    i.insert(0,"#")

    i.append("#")

maze.insert(0,["#"]*(w+2))

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





import copy

def clear_maze(maze,target=0):

    con = False

    for r,v1 in enumerate(maze):

        for c,v2 in enumerate(v1):

            if v2==target:

                con = True

                if maze[r-1][c]==".":

                    maze[r-1][c]=target+1

                if maze[r+1][c]==".":

                    maze[r+1][c]=target+1

                if maze[r][c-1]==".":

                    maze[r][c-1]=target+1

                if maze[r][c+1]==".":

                    maze[r][c+1]=target+1

    if con:

        return clear_maze(maze,target+1)

    else:

        return target - 1

ret = 0

for i in range(h+1):

    for j in range(w+1):

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

            m = copy.deepcopy(maze)

            m[i][j]=0

            ret = max(ret,clear_maze(m))



print(ret)
# -*- coding: utf-8 -*-

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

inf=float("inf")

s = [[-1]*(w+2)] + [[-1] + [inf if i=="." else -1 for i in eval(input())] + [-1] for _ in range(h)] + [[-1]*(w+2)]



from copy import deepcopy

from collections import deque



ret = 0

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

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

        temp_s = deepcopy(s)

        if temp_s[i][j]!=-1:

            temp_s[i][j]=-1

            stack_deque = deque([(i,j,0)])

        else:

            stack_deque = []

        max_v=0

        while len(stack_deque)>0:

            hi,wj,v = stack_deque.popleft()

            v+=1

            if temp_s[hi][wj-1]!=-1:

                temp_s[hi][wj-1]=-1

                stack_deque.append([hi,wj-1,v])

                max_v=max(max_v,v)

            if temp_s[hi][wj+1]!=-1:

                temp_s[hi][wj+1]=-1

                stack_deque.append([hi,wj+1,v])

                max_v=max(max_v,v)

            if temp_s[hi-1][wj]!=-1:

                temp_s[hi-1][wj]=-1

                stack_deque.append([hi-1,wj,v])

                max_v=max(max_v,v)

            if temp_s[hi+1][wj]!=-1:

                temp_s[hi+1][wj]=-1

                stack_deque.append([hi+1,wj,v])

                max_v=max(max_v,v)

        ret=max(ret,max_v)

print(ret)
# -*- coding: utf-8 -*-
h, w = list(map(int, input().split()))
maze = [list(eval(input())) for i in range(h)]
for i in maze:
    i.insert(0, "#")
    i.append("#")
maze.insert(0, ["#"] * (w + 2))
maze.append(["#"] * (w + 2))
import copy


def clear_maze(maze, target=0):
    con = False
    for r, v1 in enumerate(maze):
        for c, v2 in enumerate(v1):
            if v2 == target:
                con = True
                if maze[r - 1][c] == ".":
                    maze[r - 1][c] = target + 1
                if maze[r + 1][c] == ".":
                    maze[r + 1][c] = target + 1
                if maze[r][c - 1] == ".":
                    maze[r][c - 1] = target + 1
                if maze[r][c + 1] == ".":
                    maze[r][c + 1] = target + 1
    if con:
        return clear_maze(maze, target + 1)
    else:
        return target - 1


ret = 0
for i in range(h + 1):
    for j in range(w + 1):
        if maze[i][j] == ".":
            m = copy.deepcopy(maze)
            m[i][j] = 0
            ret = max(ret, clear_maze(m))
print(ret)

# -*- coding: utf-8 -*-
h, w = list(map(int, input().split()))
inf = float("inf")
s = (
    [[-1] * (w + 2)]
    + [[-1] + [inf if i == "." else -1 for i in eval(input())] + [-1] for _ in range(h)]
    + [[-1] * (w + 2)]
)
from copy import deepcopy
from collections import deque

ret = 0
for i in range(1, h + 1):
    for j in range(1, w + 1):
        temp_s = deepcopy(s)
        if temp_s[i][j] != -1:
            temp_s[i][j] = -1
            stack_deque = deque([(i, j, 0)])
        else:
            stack_deque = []
        max_v = 0
        while len(stack_deque) > 0:
            hi, wj, v = stack_deque.popleft()
            v += 1
            if temp_s[hi][wj - 1] != -1:
                temp_s[hi][wj - 1] = -1
                stack_deque.append([hi, wj - 1, v])
                max_v = max(max_v, v)
            if temp_s[hi][wj + 1] != -1:
                temp_s[hi][wj + 1] = -1
                stack_deque.append([hi, wj + 1, v])
                max_v = max(max_v, v)
            if temp_s[hi - 1][wj] != -1:
                temp_s[hi - 1][wj] = -1
                stack_deque.append([hi - 1, wj, v])
                max_v = max(max_v, v)
            if temp_s[hi + 1][wj] != -1:
                temp_s[hi + 1][wj] = -1
                stack_deque.append([hi + 1, wj, v])
                max_v = max(max_v, v)
        ret = max(ret, max_v)
print(ret)

-maze = [list(eval(input())) for i in range(h)] -for i in maze: -    i.insert(0, "#") -    i.append("#") -maze.insert(0, ["#"] * (w + 2)) -maze.append(["#"] * (w + 2)) -import copy - - -def clear_maze(maze, target=0): -    con = False -    for r, v1 in enumerate(maze): -        for c, v2 in enumerate(v1): -            if v2 == target: -                con = True -                if maze[r - 1][c] == ".": -                    maze[r - 1][c] = target + 1 -                if maze[r + 1][c] == ".": -                    maze[r + 1][c] = target + 1 -                if maze[r][c - 1] == ".": -                    maze[r][c - 1] = target + 1 -                if maze[r][c + 1] == ".": -                    maze[r][c + 1] = target + 1 -    if con: -        return clear_maze(maze, target + 1) -    else: -        return target - 1 - +inf = float("inf") +s = ( +    [[-1] * (w + 2)] +    + [[-1] + [inf if i == "." else -1 for i in eval(input())] + [-1] for _ in range(h)] +    + [[-1] * (w + 2)] +) +from copy import deepcopy +from collections import deque -for i in range(h + 1): -    for j in range(w + 1): -        if maze[i][j] == ".": -            m = copy.deepcopy(maze) -            m[i][j] = 0 -            ret = max(ret, clear_maze(m)) +for i in range(1, h + 1): +    for j in range(1, w + 1): +        temp_s = deepcopy(s) +        if temp_s[i][j] != -1: +            temp_s[i][j] = -1 +            stack_deque = deque([(i, j, 0)]) +        else: +            stack_deque = [] +        max_v = 0 +        while len(stack_deque) > 0: +            hi, wj, v = stack_deque.popleft() +            v += 1 +            if temp_s[hi][wj - 1] != -1: +                temp_s[hi][wj - 1] = -1 +                stack_deque.append([hi, wj - 1, v]) +                max_v = max(max_v, v) +            if temp_s[hi][wj + 1] != -1: +                temp_s[hi][wj + 1] = -1 +                stack_deque.append([hi, wj + 1, v]) +                max_v = max(max_v, v) +            if temp_s[hi - 1][wj] != -1: +                temp_s[hi - 1][wj] = -1 +                stack_deque.append([hi - 1, wj, v]) +                max_v = max(max_v, v) +            if temp_s[hi + 1][wj] != -1: +                temp_s[hi + 1][wj] = -1 +                stack_deque.append([hi + 1, wj, v]) +                max_v = max(max_v, v) +        ret = max(ret, max_v)