import sys

sys.setrecursionlimit(3000)



import numpy as np



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

s = []



for i in range(h):

    s.append(list(eval(input())))



from collections import deque



def bfs(i,j,dist):

    seen[i][j] = dist

    lis = [[i-1,j],[i,j-1],[i+1,j],[i,j+1]]

    for place in lis:

        if place[0]<0 or place[0]>=h or place[1]<0 or place[1]>=w:

            continue

        if seen[place[0]][place[1]] != -1 or s[place[0]][place[1]]=="#":

            continue

        if [place[0],place[1],dist+1] in que:

            continue

        que.append([place[0],place[1],dist+1])

    if len(que):

        new = que.popleft()

        bfs(new[0],new[1],new[2])

    else:

        return





mx = 0

for i in range(h):

    for  j in range(w):

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

            continue

        seen = [[-1 for _ in range(w)]for _ in range(h)]

        que = deque()

        bfs(i,j,0)

        ast = np.array(seen)

        tmp = np.amax(ast)

        mx = max(mx,tmp)

        #print(seen)

            #print(*seen,sep="\n")

print(mx)

import sys

sys.setrecursionlimit(3000)



import numpy as np



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

s = []



for i in range(h):

    s.append(list(eval(input())))



from collections import deque



def bfs(i,j,dist):

    lis = [[i-1,j],[i,j-1],[i+1,j],[i,j+1]]

    for place in lis:

        if place[0]<0 or place[0]>=h or place[1]<0 or place[1]>=w:

            continue

        if seen[place[0]][place[1]] != -1 or s[place[0]][place[1]]=="#":

            continue

        seen[place[0]][place[1]] = dist+1

        que.append([place[0],place[1],dist+1])

    if len(que):

        new = que.popleft()

        bfs(new[0],new[1],new[2])

    else:

        return





mx = 0

for i in range(h):

    for  j in range(w):

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

            continue

        seen = [[-1 for _ in range(w)]for _ in range(h)]

        que = deque()

        seen[i][j] = 0

        bfs(i,j,0)

        ast = np.array(seen)

        tmp = np.amax(ast)

        mx = max(mx,tmp)

        #print(seen)

            #print(*seen,sep="\n")

print(mx)

import sys

sys.setrecursionlimit(3000)
import numpy as np

h, w = list(map(int, input().split()))
s = []
for i in range(h):
    s.append(list(eval(input())))
from collections import deque


def bfs(i, j, dist):
    seen[i][j] = dist
    lis = [[i - 1, j], [i, j - 1], [i + 1, j], [i, j + 1]]
    for place in lis:
        if place[0] < 0 or place[0] >= h or place[1] < 0 or place[1] >= w:
            continue
        if seen[place[0]][place[1]] != -1 or s[place[0]][place[1]] == "#":
            continue
        if [place[0], place[1], dist + 1] in que:
            continue
        que.append([place[0], place[1], dist + 1])
    if len(que):
        new = que.popleft()
        bfs(new[0], new[1], new[2])
    else:
        return


mx = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            continue
        seen = [[-1 for _ in range(w)] for _ in range(h)]
        que = deque()
        bfs(i, j, 0)
        ast = np.array(seen)
        tmp = np.amax(ast)
        mx = max(mx, tmp)
        # print(seen)
        # print(*seen,sep="\n")
print(mx)

import sys

sys.setrecursionlimit(3000)
import numpy as np

h, w = list(map(int, input().split()))
s = []
for i in range(h):
    s.append(list(eval(input())))
from collections import deque


def bfs(i, j, dist):
    lis = [[i - 1, j], [i, j - 1], [i + 1, j], [i, j + 1]]
    for place in lis:
        if place[0] < 0 or place[0] >= h or place[1] < 0 or place[1] >= w:
            continue
        if seen[place[0]][place[1]] != -1 or s[place[0]][place[1]] == "#":
            continue
        seen[place[0]][place[1]] = dist + 1
        que.append([place[0], place[1], dist + 1])
    if len(que):
        new = que.popleft()
        bfs(new[0], new[1], new[2])
    else:
        return


mx = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            continue
        seen = [[-1 for _ in range(w)] for _ in range(h)]
        que = deque()
        seen[i][j] = 0
        bfs(i, j, 0)
        ast = np.array(seen)
        tmp = np.amax(ast)
        mx = max(mx, tmp)
        # print(seen)
        # print(*seen,sep="\n")
print(mx)

-    seen[i][j] = dist -        if [place[0], place[1], dist + 1] in que: -            continue +        seen[place[0]][place[1]] = dist + 1 +        seen[i][j] = 0