import copy
import heapq
import math
import fractions

def j(n):
    if n:print("Yes")
    else:print("No")
    exit(0)
rem = 10 ** 9 + 7

"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def ipmultiplerow(n):
    a = []
    for i in range(n):
        a.append(ip())
    return a
def printrow(a):
    for i in a:
        print(i)


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


h,w = ips()
pre  = '#'*(w+2)
board = [pre]
road = h*w
for i in range(h):
    a = input()
    road-=a.count('#')
    a = ''.join(['#',a,'#'])
    board.append(a)
board.append(pre)
maxsteps = 0
bh = h+2
bw = w+2
notfar = set()
for by in range(1,h+1):
    for bx in range(1,w+1):
        que = []
        checked = []
        if board[by][bx] == '.' and bw*by+bx not in notfar:
            #print("start",by,bx,by*bw+bx)
            que = []
            checked = [bw*by+bx]
            steps = 0
            if board[by][bx - 1] == '.':que.append([by,bx-1])
            if board[by][bx + 1] == '.':que.append([by,bx+1])
            if board[by - 1][bx] == '.':que.append([by-1,bx])
            if board[by + 1][bx] == '.':que.append([by+1,bx])
            while len(que):
                next = len(que)
                oldque = copy.copy(que)
                que = copy.copy([])
                for i in range(len(oldque)):
                    y,x = oldque[i] #need to change here
                    checked.append(y*bw+x)
                    if board[y][x - 1] == '.' and bw*y+x-1 not in checked: que.append([y, x - 1])
                    if board[y][x + 1] == '.' and bw*y+x+1 not in checked: que.append([y, x + 1])
                    if board[y - 1][x] == '.' and bw*(y-1)+x not in checked: que.append([y - 1, x])
                    if board[y + 1][x] == '.' and bw*(y+1)+x not in checked: que.append([y + 1, x])
                steps+=1
                if len(que):
                    for i in range(len(oldque)):
                        y, x = oldque[i]
                        notfar.add(bw*y+x)
                #print("che",checked)
                #print("que",que)
            maxsteps = max(steps,maxsteps)
print(maxsteps)